0

I know there is something wrong with my code and seeing as this is my hello world project I am very confused. I have read other posts but nothing will work. Can somebody make this work for me??.

The HTML

<html>
<head>
    <link rel="stylesheet" href="game.css">
</head>
<body onload="startgame()">
    <div id=content>
    <center>
    <div id=pricediv>
        <p id=price></p>
    </div>
    <div id=buysell>
        <button class=buy>Buy</button>
        <button class=sell>Sell</button>
        <button onclick="startgame()">Start</button>
    </div>
    </center>
    </div>
</body>

The JavaScript

var paused = "false";


function startgame() {
while (paused === false) {
    var price = Math.round(Math.random());
    document.getElementById("price").innerHTML = price;
}
}
0

2 Answers 2

0

<p> tags don't have value. Use innerHTML instead.

Also "price" will display word price instead of variable, so drop the quotes:

document.getElementById("price").innerHTML= price
Sign up to request clarification or add additional context in comments.

3 Comments

While this helps, it did not fix my problem as the page is still not showing the variable
It might be also caused by the fact that "false" is not strictly equal to false - one is a string and the other isn't
..and also mind that this loop in it's current state would just repeatedly replace the value in the paragraph, freezing the page.
0

Use .innerHTML instead of .value.

.value is used to set the value of an input element, ie. <input> or <textarea>.

.innerHTMl is used to set the string value in between a html tag, ie. <h1>, <p> or <div>.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.