I am following this online free course on YouTube, this is the link if you want to visit it:
“text”, but at around 2:15:00, he shows how to call javascript variables in HTML tags and log them onto the console. My problem is that It doesn’t show the variables value in the console log when I do the same as him.
for example, if I write Show amount and I have a variable in a script with a name value and a value of 0, it will show a space in the console when I click the button but for the guy, it shows the actual value (which is 0). what could be the reason? I would appreciate any help you could give regarding the matter.
i am still beginner so it will be better if it is explained in simple language
my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>javascript loggin</title>
</head>
<body>
<!--my comment is mine-->
<button onclick="
console.log('hello world' + value)
">ad</button>
<script>
let value = 0;
value = 3
</script>
</body>
</html>
Here is an image of the guys code: (If image isn’t loaded, his concept is pretty much same as mine.)
For me when i click the button it shows the string placed within the console.log but fails to call and show the variable. the only way i can display the variable is by putting the console.log within the script otherwise it doesn’t work anywhere else in the html file.
Rahand hemin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.