Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Want to see if you'll win a discount?

Click on the button to see if you land 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

ISBN: 1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

Different formulas for mathematical core areas.

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago