JavaScript Explained
Here's an explanation of this code in bullet points:
- The page is built in HTML with CSS styles and JavaScript interactivity.
- It contains two main sections: a quiz section and a standings section.
- The quiz section features two buttons, each representing a team in the NHL.
- The standings section displays a list of the teams based on the quiz progression.
Breaking it down:
-
HTML
- The page has a title "NHL Standings Quiz".
- There are two main
divcontainers: one for the quiz (class="quiz-container") and one for displaying the standings (class="standings-container"). - In the quiz container, there's a heading and two buttons (using
ptags with classteam-button) that, when clicked, call a functionselectTeamwith an argument of 0 or 1. - There's also a feedback paragraph with an
id="feedback"to provide feedback to the user. - The standings container displays an ordered list (
ol), withid="standings", which will contain the team standings as list items (li).
-
CSS
- The styling is used to create a centered, vertical layout for the page. The background color is set, the font is selected, and the page is made to fit the entire viewport height.
- The
.quiz-containerand.standings-containerdivs are styled to be visually distinguishable and to provide a good user experience. - The buttons are styled for a more engaging interface. They have a specified color, size, and cursor style. They also have a hover effect that changes their color when the mouse pointer is over them.
-
JavaScript
- The script defines a list of NHL team names in the
standingsarray. - It also sets up variables (
currentIndex,remainingTeams,correctIndex) to track the state of the quiz. - The
loadTeamsfunction is used to set the names on the two team buttons. One team is selected randomly from the remaining teams (not including the current team) and the other is the current team. One button is assigned the correct team and the other button the randomly chosen team. - The
selectTeamfunction is called when a team button is clicked. If the correct team is selected, the team is removed from theremainingTeamsarray, and theloadTeamsfunction is called to get the next set of teams. If the wrong team is selected, a feedback message "Try again!" is displayed. - The
updateStandingsfunction is used to update the displayed standings. It creates a new list item for each team that has been through the quiz and adds it to the standings list. - The
loadTeamsfunction is called initially when the page loads to start the quiz.
- The script defines a list of NHL team names in the