The following code is not quite working.
Here is a couple of my observations:
1- No matter what the user guesses, the message "You Win!" Always show up
2- Console.log(yourguess) shows a blank space
Code:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Lab12</title>
<style>
</style>
</head>
<body>
<p>Guess a number between 1 and 1000:</p>
<input type="text" id="theguess"> <br>
<button type="button" onclick="calc()" id="thebutton">Check Guess</button>
<p id="clue">No Guess Yet</p>
<p>You guessed</p>
<p id="c"> 0 </p>
<p>Times!</p>
<br>
</body>
</html>
Javascript:
<script>
let correct = Math.floor(Math.random() * 1000);
let yourguess = document.getElementById("theguess").value;
let count = 0;
calc = () => {
console.log(yourguess)
if (thebutton) {
count++
document.getElementById('c').innerHTML = count;
}
if (count === 10) {
document.getElementById("thebutton").disabled = true;
}
if (this.correct === this.yourguess) {
document.getElementById('clue').innerHTML = 'You Win!';
}
else if (this.correct < this.yourguess) {
document.getElementById('clue').innerHTML = 'Too low. Try Higher!';
}
else{
document.getElementById('clue').innerHTML = 'Too High. Try Lower!';
}
}
</script>
There is no syntax error, which is why I can't quite point my finger on where the error is
Stackoverflow people, do your thing!
thebuttonvariable.