Question
I'm trying to get a number generated between 1 and 10 that might match what the user input in the input box for that number.
I'm trying to get a number generated between 1 and 10 that might match what the user input in the input box for that number. I can get one of the messages to show up but not the other. I'm just trying to make sure that this is working as intended. The message of if you got a discount or not is supposed to show up between the input and the submit button.
HTML
Click on the button to see if you land a discount!Want to see if you'll win a discount?
CSS
/* Discount Section */ .discount { margin: 0 auto; width: var(--width); text-align: center; padding-bottom: 100px; padding-top: 50px; }
.discount form { display: flex; flex-direction: column; }
.discount h2 { color: var(--mint); }
.discount .guessingGame label { font-family: var(--other-font); text-align: center; margin-top: 10px; margin-bottom: 10px; margin-left: auto; margin-right: auto; }
.discount .guessingGame input { margin-bottom: 10px; margin-left: auto; margin-right: auto; width: 200px; }
.guessingGame { display: block; }
.guessingGame input#submitButton { margin-top: 30px; width: 250px; }
JavaScript
function randomNum() { let randNum = Math.floor(Math.random() * 10) + 1; let numInput = document.getElementById("userInput"); let userInput = numInput.value; let output = document.getElementById("message"); if (randNum === userInput.value) { output.innerHTML = "You've won a $7 discount!"; } else if (randNum !== userInput.value) { output.innerHTML = "Sorry no discounts for you. Try again!"; } event.preventDefault(); output = ""; }
// event listener for random number generator document.getElementById("submitButton").addEventListener("click", randomNum);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started