Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

MULTIPLE ARRAYS QUIZ: Inability to get my hard-coded function to fire up upon page load.

My "quesitons" funciton does not fire up upon page load. I have re-watched videos and researched online.

I am snow-blind at this point after hours of trying to find out what is the problem. Thanks for any finding the problem for me.

The Code:

// 1. Create a multidimensional array to hold quiz questions and answers

const quiz2nd =

  [
  [ 'How many states in the United States?', 50 ],
  [ 'How may rivers does the State of Illinois use as its border?', 2 ],
  [ 'How many electoral votes does is required to be accumulated by a candidate to win the Untied States Presidental Election?', 270 ],
  [ 'What was the "authorized strenth" of a World War II USA tank platoon in the European Theatre circa 1944-45?', 5 ],
  [ 'What American sport has its regulation time set by not by "x" units of time but by how many units of "y"?', 9 ]
  ];

// 2. Store the number of questions answered correctly

let matched = 0; // Keeps track of the number of correctly selected answers.

/*

  1. Use a loop to cycle through each question
    • Present each question to the user
    • Compare the user's response to answer in the array
    • If the response matches the answer, the number of correctly answered questions increments by 1 */

const questions = function() {

 for  ( let i  = 0; i < quiz2nd.length; i++ )   {

     let userChoice = prompt( `${ quiz2nd[i][0] }` );

     let answer = `${ quiz2nd[i][1] }`;

 //OKAY UP THROUGH HERE 20:53 AUG 12, 2020

          if  ( !Number.isInteger( +userChoice ) )  {
        alert('Please enter an integer.');
                userChoice = null;
            i--  // redo this iteration of i       

       }  else if ( userChoice !== answer )  {
                console.log( 'Wrong Choice ' + userChoice  );

           }  else  {
        matched =  matched + 1;  // 

       } // END IF

              // ***************  MY ARCAIC OPERA BROWSER (WIN XP) IS NOT ALLOWING "+=" TO UPTICK THE TICKER VARIABLE ***********                         // ***************  REGARDLESS IF I FOLLOW THE += WITH A ";" OR NOT ***********************************************

 }  // End FOR Loop

// 4. Display the number of correct answers to the user

document.querySelector('main').innerHTML = You seleced <p>${ matched }</p> correct answers.;

}; // End Function

// Call the function

questions();

/******************************** END OF SCRIPT 23:14 AUG 12, 2020 ********************************************************************/

1 Answer

Steven Parker
Steven Parker
231,140 Points

It's the HTML part of the code that loads the JavaScript and starts it running. But that code isn't shown here.

To share the entire project at once (and avoid losing special characters), you can make a snapshot of your workspace and post the link to it here.