Hello everyone, I created variables and I wanted to display data from variables with document.write. The problem is when I run the code with one of the browsers it doesn’t show me anything. I am a beginner in JavaScript and every tip and suggestion will mean a lot to me. Here is my code
<!Doctype html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<script type="text/javascript">
var x=r;
var y=1510;
window.document.write(x);
document.write("<hr>");
document.write(y);
</script>
</body>
</html>
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
You should create a name variable that makes sense, as well strings with quotes with a specific name like:
var myString = "myLetterString"; // with quotes around to identify a string letter.
window.document.write(myString); // output --> myLetterString
I suggest you try to do console.log() to see any output. Also like @JeremyLT it’s better not to write document.write might run into a remove existing strings. and better to do DOM manipulation.