0

For example, there is a page like below.

<html>
<head>
<title>Variables!!!</title>
<script type="text/javascript">
var lookatthis = 11;
var one = 22;
var two = 3;
var add = one + two;
var minus = one - two;
var multiply = one * two;
var divide = one/two;
    document.write("First No: = " + one + "<br />Second No: = " + two + " <br />");
    document.write(one + " + " + two + " = " + add + "<br/>");
    document.write(one + " - " + two + " = " + minus + "<br/>");
    document.write(one + " * " + two + " = " + multiply + "<br/>");
    document.write(one + " / " + two + " = " + divide + "<br/>");
</script>
</head>
<body>
</body>
</html>

I want to assign the javascript variable "lookatthis" on debug console.

//apologise for my ambiguous question. I would rather say, "I want to assign new value to variable "lookatthis" on this web-page using console on explorer."

Thank you for your kind teaching.)

2
  • 2
    put a debugger and then assign it from the console. What difficulty do you face in that? Commented Mar 19, 2019 at 8:07
  • If it's an input then it's Element.value = lookatthis;, otherwise it's Element.innerHTML = lookatthis;. Element can be gotten, via document.getElementById('yourHTMLidHere') or any number of DOM methods. Make sure you escape .innerHTML special characters. Refrain from using document.write whenever possible (which is always). Commented Mar 19, 2019 at 8:13

5 Answers 5

1

Open debug console and write there:

lookatthis = 20

But this get you nothing

Sign up to request clarification or add additional context in comments.

Comments

0

You can use the log method:

console.log(lookatthis);

2 Comments

OP wants to assign the variable, not print it
From the "variety" of answers we can deduce that the question indeed is unclear. So we will wait the decision of the asker to accept (perhaps) one the answers and clear the doubts. :)
0

Anywhere in your script block after your initial assignment of lookatthis, you can write the value to the console with the command:

console.log(lookatthis);

Comments

0

You achieve it by using prompt function

var lookatthis = prompt('Type the lokaltthis value');

Comments

0

If what you want is to be able to 'set' the value of lookatthis, you can use an input and using jquery or pure js get the value of the input and assign it to 'lookatthis'.

Edit: You can also use in the chrome console: lookatthis=25 but as your script loads when page loads, changes will not be shown but the value will be changed

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.