Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The below html5 code will not output the document.getElementById line for some r

ID: 3593239 • Letter: T

Question

The below html5 code will not output the document.getElementById line for some reason. Please help! Thanks in advance.

code:

<!DOCTYPE html>

<!--

-->

<html>

<head>

<title> Guess My Number! </title>

</head>

<body>

<script>

function numberGuess(){

var numb = Math.floor((Math.random() * 10);

var name = document.getElementById('name').value;

var guess = document.getElementById('guess').value;

var outputAns;

var answer;

if(guess < numb){

answer = (name + ", your guess was too low!");

}

else if(guess > numb){

answer = (name + ", your guess was too high!");

}

else{

answer = (name + ", your guess was just right!");

}

document.getElementById('outputAns').innerHTML = answer;

}

</script>

<h2> Guess My Number! </h2>

<p>Valid numbers are: 1 through 100</p>

<p>Enter your name: <input id="name" type="text"></p>

<p>Guess a number: <input id="guess" type="number" min="0" max="100"></p>

<h2 id="outputAns"></h2>

</body>

</html>

Explanation / Answer

<html>
<head>
<title> Guess My Number! </title>
</head>
<body>
<script>

function numberGuess(){
var numb = Math.floor(Math.random() * 10);
var name = document.getElementById('name').value;
var guess = document.getElementById('guess').value;
var outputAns;
var answer;
if(guess < numb){
answer = (name + ", your guess was too low!");
}
else if(guess > numb){
answer = (name + ", your guess was too high!");
}
else{
answer = (name + ", your guess was just right!");
}
document.getElementById('outputAns').innerHTML = answer;
}
</script>
<h2> Guess My Number! </h2>
<p>Valid numbers are: 1 through 100</p>
<p>Enter your name: <input id="name" type="text"></p>
<p>Guess a number: <input id="guess" type="number" min="0" max="100"></p>
<h2 id="outputAns"></h2>
</body>
</html>

The mistake which you did:

*********************************

var numb = Math.floor((Math.random() * 10);

Over all program is correct,the only mistake is you kept one extra brace which i have bold.

Which i corrected is:

***************************

var numb = Math.floor(Math.random() * 10);

This is the way you have to write and once try it.

Thanks and Regards,

Plese feel free to reach me ,if any doubts.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote