Skip to content

kqarlos/code-quiz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Code Quiz 📝


Languages Top Language Code Size Repo Size Total Lines Last Commit Issues Followers

Description

This application will test your knowledge of javascript, css and html! Answer the questions under the time alloted. Each correct question will give you 5 points. Every incorrect question will substract 10 seconds from the timer. At the end, any extra time will be added to the final score. At the end you can save your final score and add to the list of high scores.

Table of Contents

Installation

This application is compatible with the most commonly used web browsers.

Live Site

## Usage

Screenshots

  1. Welcome

Welcome

  1. Quiz

Quiz

  1. Input Score

Input

  1. High Scores

HighScores

Snippets

  1. Submit Score: This event listener is tied to the submitInitials button. Once clicked, it shows most of the manipulation that happens in the local storage. First it trims the value of the input and checks if it's empty. Then, it creates a new object with the user's initials and their score. Then, it retrieves the array of user objects from the local storage if there is one. Then, it pushes the created object to the array and saves it to the local storage. All objects saved to the local storage consist of a username, a userScore, and their respective values.
submitInitialsBtnEl.addEventListener("click", function () {
    let initValue = initialsEl.value.trim();
    if (initValue) {
        let userScore = { username: initValue, userScore: score };
        initialsEl.value = '';
        highScores = JSON.parse(localStorage.getItem("scores")) || [];
        highScores.push(userScore)
        localStorage.setItem("scores", JSON.stringify(highScores));
        hide(inputScoreEl);
        renderHighScores();
        reset();
    }
});
  1. Timer: This shows the time manipulation that starts as soon as the quiz starts. The startTimer() function starts and updates the timer on the screen every 1000 milliseconds. It also checks every iteration if the time is up so the timer and the quiz can be stopped. The stopTimer() function is called once the time is up or once the user is done with the last question of the quiz.
function startTimer() {
    timerEl.textContent = timeGiven;
    interval = setInterval(function () {
        secondsElapsed  ;
        timerEl.textContent = timeGiven - secondsElapsed;
        if (secondsElapsed >= timeGiven) {
            currentQ = questions.length;
            nextQuestion();
        }
    }, 1000);
}

function stopTimer() {
    clearInterval(interval);
}
    

Credits

Author

Built With

HMTL CSS Javascript Bootstrap


License

MIT license