Create a web page named lab3html you can format the page


Create a web page named lab3.html. You can format the page any way that you like. Give the page a title and heading.

Create an external JavaScript file with the following:
Create an array of at least 3 trivia questions. You can use the array from lab 2 if you like.
Create a second array that contains the answers to the trivia questions in the same position as the questions.
Initialize a score variable to 0
Create a for loop that will use a counter from 0 to 2 (to correspond to the arrays). Inside the loop you should:
Call the quiz function (see below) passing the loop counter as a parameter.
The quiz function will return a point value. Save the point value in a variable and add it to the score.
close the loop
After the for loop is complete, write out the score to the page.
Create the quiz function that accepts one parameter which is the counter.
Initialize a guesses variable to 3. This will be used to count down the number of attempts the user has to answer the question correctly.
Create a while loop to run as long as guesses > 0. Inside the while loop:
prompt the user to answer the trivia question using the counter parameter as the array index.
compare the answer entered by the user to the corresponding answer in the answers array
If they answer correctly
return the guesses variable (Note: if the user gets it right on the first guess, it will return 3 for the points. If it's the second guess, it will return 2 and the third guess 1)
else
subtract 1 from guesses
close the loop
After the while loop, return 0 to the calling script. (Note: if the user never got it right, we are return a point value of 0.
Be sure to link the external JavaScript file to the web page.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create a web page named lab3html you can format the page
Reference No:- TGS02398335

Now Priced at $20 (50% Discount)

Recommended (93%)

Rated (4.5/5)