Your Perfect Assignment is Just a Click Away

We Write Custom Academic Papers

100% Original, Plagiarism Free, Customized to your instructions!

glass
pen
clip
papers
heaphones

Conditional statements, loops and functions in a JavaScript script

Conditional statements, loops and functions in a JavaScript script

Question Description

Lab 3

Objective: Use conditional statements, loops and functions in a JavaScript script

Description:

For this lab, we are going to create a quiz. The quiz questions will be stored in one array and the corresponding answers will be stored in a second array. We will loop through the question array to prompt the user for the answer. When they enter an answer, we will compare that to the answers array. If it matches they get the points. If not, then they get 2 more tries to answer it correctly. If they get it right in 3 tries, they get points. If not, then no points. As soon as they answer it correctly or if the 3 tries expire, then move on to the next question. We will be using conditional statements (if), for and while loops and functions in this lab.

Requirements:

  • 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.
  • Upload your files to the server. Test and submit the assignment.
Lab Requirement Point Value
Create a Web page named Lab3.html. You can format the page any way that you like

5 points

Create an external JavaScript file and link it to your page 5 points

Create the questions and answers arrays with 3 elements each

5 points

Create the for loop to call the quiz function and add points to the score

10 points

Write out the score to the page

5 points

Create the quiz function with 1 parameter 10 points
Create the while loop based on guesses

10 points

Prompt the user with the question from the array 5 points
Use an if statement to compare the user’s answer to the answer array 10 points
Return a point value 5 points
Script executes correctly on the server

5 points

Total:

75 points

Order Solution Now

Our Service Charter

1. Professional & Expert Writers: Course Elite only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Course Elite are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Course Elite is known for timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Course Elite, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.