Skip to content

Dev#1

Open
abusaddique95 wants to merge 12 commits intomainfrom
dev
Open

Dev#1
abusaddique95 wants to merge 12 commits intomainfrom
dev

Conversation

@abusaddique95
Copy link
Owner

No description provided.

const onLoad = () => {
// initialise local storage

const readFromLocalStorage = (key, defaultValue) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this function to the global scope as it is within the onLoad function and only scoped to the onLoad function. Your local storage feature is not working because this function is not accessible where it is being called.

}
};

const writeToLocalStorage = (key, value) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this function to the global scope as it is within the onLoad function and only scoped to the onLoad function. Your local storage feature is not working because this function is not accessible where it is being called.

let quizComplete = false;
let timerId;

const onLoad = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After you move the 2 local storage functions to global you can delete the onLoad function as it is not required as it isn't being called anywhere.

getScore: getScore,
};

const finalScores = readFromLocalStorage(finalScores, []);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using the readFromLocalStorage function to read the data from local storage and not passing in the key of "finalScores" as a string. Please use suggested code.

Suggested change
const finalScores = readFromLocalStorage(finalScores, []);
const finalScores = readFromLocalStorage("finalScores", []);


writeToLocalStorage("finalScores", finalScore);

formComplete.addEventListener("submit", handleFormSubmit);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this to the end of the file along with the other event listener. You cannot add an event listener to a function that is called by the event listener

};

const handleFormSubmit = (event) => {
const formComplete = document.getElementById("form-complete");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this to the start of the file with all the other elements you are targeting


const handleFormSubmit = (event) => {
const formComplete = document.getElementById("form-complete");
const fullNameInput = document.getElementById("full-name-input");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using incorrect id, please check in your HTML, use suggested code

Suggested change
const fullNameInput = document.getElementById("full-name-input");
const fullNameInput = document.getElementById("full-name");

const handleFormSubmit = (event) => {
const formComplete = document.getElementById("form-complete");
const fullNameInput = document.getElementById("full-name-input");
const getScore = document.getElementById("form-hs");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bringing back the entire element as your score, but your score is the current timerValue. Please use the suggested code

Suggested change
const getScore = document.getElementById("form-hs");
const getScore = timerValue;

const finalScores = readFromLocalStorage(finalScores, []);
finalScores.push(finalScore);

writeToLocalStorage("finalScores", finalScore);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to push the array which contains the score and not the score object only. Please use suggested code.

Suggested change
writeToLocalStorage("finalScores", finalScore);
writeToLocalStorage("finalScores", finalScores);


const renderQuizCompleteSection = () => {
// use HTML as guide and build in JS
const quizFinished = document.getElementById("quiz-complete");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This element is not anywhere on the page and I can see that is commented out in code. Maybe add a display: none css property to that element like the others and when quiz is complete you can remove that class to show the element.

@@ -0,0 +1,3 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this file as it is specific to your vs code. To avoid this you can add a .gitignore file with the content:

.vscode

<button id="start-quiz-btn" class="start-btn">Start Quiz</button>
</section>

<!-- <section id="question-list">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused code which is commented out.

</form>
</section>

<!-- <section id="game-over-section" class="game-over">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused code which is commented out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants