Skip to content

Commit d792edc

Browse files
committed
Removed console.logs
1 parent 63d7363 commit d792edc

File tree

12 files changed

+202
-216
lines changed

12 files changed

+202
-216
lines changed

10. Fetch Questions from Local JSON File/end.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ username.addEventListener('keyup', () => {
1414
});
1515

1616
saveHighScore = (e) => {
17-
console.log('clicked the save button!');
1817
e.preventDefault();
1918

2019
const score = {
Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const question = document.getElementById("question");
2-
const choices = Array.from(document.getElementsByClassName("choice-text"));
3-
const progressText = document.getElementById("progressText");
4-
const scoreText = document.getElementById("score");
5-
const progressBarFull = document.getElementById("progressBarFull");
1+
const question = document.getElementById('question');
2+
const choices = Array.from(document.getElementsByClassName('choice-text'));
3+
const progressText = document.getElementById('progressText');
4+
const scoreText = document.getElementById('score');
5+
const progressBarFull = document.getElementById('progressBarFull');
66
let currentQuestion = {};
77
let acceptingAnswers = false;
88
let score = 0;
@@ -11,79 +11,78 @@ let availableQuesions = [];
1111

1212
let questions = [];
1313

14-
fetch("questions.json")
15-
.then(res => {
16-
return res.json();
17-
})
18-
.then(loadedQuestions => {
19-
console.log(loadedQuestions);
20-
questions = loadedQuestions;
21-
startGame();
22-
})
23-
.catch(err => {
24-
console.error(err);
25-
});
14+
fetch('questions.json')
15+
.then((res) => {
16+
return res.json();
17+
})
18+
.then((loadedQuestions) => {
19+
questions = loadedQuestions;
20+
startGame();
21+
})
22+
.catch((err) => {
23+
console.error(err);
24+
});
2625

2726
//CONSTANTS
2827
const CORRECT_BONUS = 10;
2928
const MAX_QUESTIONS = 3;
3029

3130
startGame = () => {
32-
questionCounter = 0;
33-
score = 0;
34-
availableQuesions = [...questions];
35-
getNewQuestion();
31+
questionCounter = 0;
32+
score = 0;
33+
availableQuesions = [...questions];
34+
getNewQuestion();
3635
};
3736

3837
getNewQuestion = () => {
39-
if (availableQuesions.length === 0 || questionCounter >= MAX_QUESTIONS) {
40-
localStorage.setItem("mostRecentScore", score);
41-
//go to the end page
42-
return window.location.assign("/end.html");
43-
}
44-
questionCounter++;
45-
progressText.innerText = `Question ${questionCounter}/${MAX_QUESTIONS}`;
46-
//Update the progress bar
47-
progressBarFull.style.width = `${(questionCounter / MAX_QUESTIONS) * 100}%`;
38+
if (availableQuesions.length === 0 || questionCounter >= MAX_QUESTIONS) {
39+
localStorage.setItem('mostRecentScore', score);
40+
//go to the end page
41+
return window.location.assign('/end.html');
42+
}
43+
questionCounter++;
44+
progressText.innerText = `Question ${questionCounter}/${MAX_QUESTIONS}`;
45+
//Update the progress bar
46+
progressBarFull.style.width = `${(questionCounter / MAX_QUESTIONS) * 100}%`;
4847

49-
const questionIndex = Math.floor(Math.random() * availableQuesions.length);
50-
currentQuestion = availableQuesions[questionIndex];
51-
question.innerText = currentQuestion.question;
48+
const questionIndex = Math.floor(Math.random() * availableQuesions.length);
49+
currentQuestion = availableQuesions[questionIndex];
50+
question.innerText = currentQuestion.question;
5251

53-
choices.forEach(choice => {
54-
const number = choice.dataset["number"];
55-
choice.innerText = currentQuestion["choice" + number];
56-
});
52+
choices.forEach((choice) => {
53+
const number = choice.dataset['number'];
54+
choice.innerText = currentQuestion['choice' + number];
55+
});
5756

58-
availableQuesions.splice(questionIndex, 1);
59-
acceptingAnswers = true;
57+
availableQuesions.splice(questionIndex, 1);
58+
acceptingAnswers = true;
6059
};
6160

62-
choices.forEach(choice => {
63-
choice.addEventListener("click", e => {
64-
if (!acceptingAnswers) return;
61+
choices.forEach((choice) => {
62+
choice.addEventListener('click', (e) => {
63+
if (!acceptingAnswers) return;
6564

66-
acceptingAnswers = false;
67-
const selectedChoice = e.target;
68-
const selectedAnswer = selectedChoice.dataset["number"];
65+
acceptingAnswers = false;
66+
const selectedChoice = e.target;
67+
const selectedAnswer = selectedChoice.dataset['number'];
6968

70-
const classToApply =
71-
selectedAnswer == currentQuestion.answer ? "correct" : "incorrect";
69+
const classToApply =
70+
selectedAnswer == currentQuestion.answer ? 'correct' : 'incorrect';
7271

73-
if (classToApply === "correct") {
74-
incrementScore(CORRECT_BONUS);
75-
}
72+
if (classToApply === 'correct') {
73+
incrementScore(CORRECT_BONUS);
74+
}
7675

77-
selectedChoice.parentElement.classList.add(classToApply);
76+
selectedChoice.parentElement.classList.add(classToApply);
7877

79-
setTimeout(() => {
80-
selectedChoice.parentElement.classList.remove(classToApply);
81-
getNewQuestion();
82-
}, 1000);
83-
});
78+
setTimeout(() => {
79+
selectedChoice.parentElement.classList.remove(classToApply);
80+
getNewQuestion();
81+
}, 1000);
82+
});
8483
});
8584

86-
incrementScore = num => {
87-
score += num;
88-
scoreText.innerText = score;
85+
incrementScore = (num) => {
86+
score += num;
87+
scoreText.innerText = score;
8988
};

11. Fetch API Questions from Open Trivia API/end.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ username.addEventListener('keyup', () => {
1414
});
1515

1616
saveHighScore = (e) => {
17-
console.log('clicked the save button!');
1817
e.preventDefault();
1918

2019
const score = {

11. Fetch API Questions from Open Trivia API/game.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ fetch(
1818
return res.json();
1919
})
2020
.then((loadedQuestions) => {
21-
console.log(loadedQuestions.results);
2221
questions = loadedQuestions.results.map((loadedQuestion) => {
2322
const formattedQuestion = {
2423
question: loadedQuestion.question,

12. Create a Spinning Loader/end.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ username.addEventListener('keyup', () => {
1414
});
1515

1616
saveHighScore = (e) => {
17-
console.log('clicked the save button!');
1817
e.preventDefault();
1918

2019
const score = {

12. Create a Spinning Loader/game.js

Lines changed: 83 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const question = document.getElementById("question");
2-
const choices = Array.from(document.getElementsByClassName("choice-text"));
3-
const progressText = document.getElementById("progressText");
4-
const scoreText = document.getElementById("score");
5-
const progressBarFull = document.getElementById("progressBarFull");
6-
const loader = document.getElementById("loader");
7-
const game = document.getElementById("game");
1+
const question = document.getElementById('question');
2+
const choices = Array.from(document.getElementsByClassName('choice-text'));
3+
const progressText = document.getElementById('progressText');
4+
const scoreText = document.getElementById('score');
5+
const progressBarFull = document.getElementById('progressBarFull');
6+
const loader = document.getElementById('loader');
7+
const game = document.getElementById('game');
88
let currentQuestion = {};
99
let acceptingAnswers = false;
1010
let score = 0;
@@ -14,101 +14,100 @@ let availableQuesions = [];
1414
let questions = [];
1515

1616
fetch(
17-
"https://opentdb.com/api.php?amount=10&category=9&difficulty=easy&type=multiple"
17+
'https://opentdb.com/api.php?amount=10&category=9&difficulty=easy&type=multiple'
1818
)
19-
.then(res => {
20-
return res.json();
21-
})
22-
.then(loadedQuestions => {
23-
console.log(loadedQuestions.results);
24-
questions = loadedQuestions.results.map(loadedQuestion => {
25-
const formattedQuestion = {
26-
question: loadedQuestion.question
27-
};
28-
29-
const answerChoices = [...loadedQuestion.incorrect_answers];
30-
formattedQuestion.answer = Math.floor(Math.random() * 4) + 1;
31-
answerChoices.splice(
32-
formattedQuestion.answer - 1,
33-
0,
34-
loadedQuestion.correct_answer
35-
);
36-
37-
answerChoices.forEach((choice, index) => {
38-
formattedQuestion["choice" + (index + 1)] = choice;
39-
});
40-
41-
return formattedQuestion;
19+
.then((res) => {
20+
return res.json();
21+
})
22+
.then((loadedQuestions) => {
23+
questions = loadedQuestions.results.map((loadedQuestion) => {
24+
const formattedQuestion = {
25+
question: loadedQuestion.question,
26+
};
27+
28+
const answerChoices = [...loadedQuestion.incorrect_answers];
29+
formattedQuestion.answer = Math.floor(Math.random() * 4) + 1;
30+
answerChoices.splice(
31+
formattedQuestion.answer - 1,
32+
0,
33+
loadedQuestion.correct_answer
34+
);
35+
36+
answerChoices.forEach((choice, index) => {
37+
formattedQuestion['choice' + (index + 1)] = choice;
38+
});
39+
40+
return formattedQuestion;
41+
});
42+
43+
startGame();
44+
})
45+
.catch((err) => {
46+
console.error(err);
4247
});
4348

44-
startGame();
45-
})
46-
.catch(err => {
47-
console.error(err);
48-
});
49-
5049
//CONSTANTS
5150
const CORRECT_BONUS = 10;
5251
const MAX_QUESTIONS = 3;
5352

5453
startGame = () => {
55-
questionCounter = 0;
56-
score = 0;
57-
availableQuesions = [...questions];
58-
getNewQuestion();
59-
game.classList.remove("hidden");
60-
loader.classList.add("hidden");
54+
questionCounter = 0;
55+
score = 0;
56+
availableQuesions = [...questions];
57+
getNewQuestion();
58+
game.classList.remove('hidden');
59+
loader.classList.add('hidden');
6160
};
6261

6362
getNewQuestion = () => {
64-
if (availableQuesions.length === 0 || questionCounter >= MAX_QUESTIONS) {
65-
localStorage.setItem("mostRecentScore", score);
66-
//go to the end page
67-
return window.location.assign("/end.html");
68-
}
69-
questionCounter++;
70-
progressText.innerText = `Question ${questionCounter}/${MAX_QUESTIONS}`;
71-
//Update the progress bar
72-
progressBarFull.style.width = `${(questionCounter / MAX_QUESTIONS) * 100}%`;
73-
74-
const questionIndex = Math.floor(Math.random() * availableQuesions.length);
75-
currentQuestion = availableQuesions[questionIndex];
76-
question.innerText = currentQuestion.question;
77-
78-
choices.forEach(choice => {
79-
const number = choice.dataset["number"];
80-
choice.innerText = currentQuestion["choice" + number];
81-
});
82-
83-
availableQuesions.splice(questionIndex, 1);
84-
acceptingAnswers = true;
63+
if (availableQuesions.length === 0 || questionCounter >= MAX_QUESTIONS) {
64+
localStorage.setItem('mostRecentScore', score);
65+
//go to the end page
66+
return window.location.assign('/end.html');
67+
}
68+
questionCounter++;
69+
progressText.innerText = `Question ${questionCounter}/${MAX_QUESTIONS}`;
70+
//Update the progress bar
71+
progressBarFull.style.width = `${(questionCounter / MAX_QUESTIONS) * 100}%`;
72+
73+
const questionIndex = Math.floor(Math.random() * availableQuesions.length);
74+
currentQuestion = availableQuesions[questionIndex];
75+
question.innerText = currentQuestion.question;
76+
77+
choices.forEach((choice) => {
78+
const number = choice.dataset['number'];
79+
choice.innerText = currentQuestion['choice' + number];
80+
});
81+
82+
availableQuesions.splice(questionIndex, 1);
83+
acceptingAnswers = true;
8584
};
8685

87-
choices.forEach(choice => {
88-
choice.addEventListener("click", e => {
89-
if (!acceptingAnswers) return;
86+
choices.forEach((choice) => {
87+
choice.addEventListener('click', (e) => {
88+
if (!acceptingAnswers) return;
9089

91-
acceptingAnswers = false;
92-
const selectedChoice = e.target;
93-
const selectedAnswer = selectedChoice.dataset["number"];
90+
acceptingAnswers = false;
91+
const selectedChoice = e.target;
92+
const selectedAnswer = selectedChoice.dataset['number'];
9493

95-
const classToApply =
96-
selectedAnswer == currentQuestion.answer ? "correct" : "incorrect";
94+
const classToApply =
95+
selectedAnswer == currentQuestion.answer ? 'correct' : 'incorrect';
9796

98-
if (classToApply === "correct") {
99-
incrementScore(CORRECT_BONUS);
100-
}
97+
if (classToApply === 'correct') {
98+
incrementScore(CORRECT_BONUS);
99+
}
101100

102-
selectedChoice.parentElement.classList.add(classToApply);
101+
selectedChoice.parentElement.classList.add(classToApply);
103102

104-
setTimeout(() => {
105-
selectedChoice.parentElement.classList.remove(classToApply);
106-
getNewQuestion();
107-
}, 1000);
108-
});
103+
setTimeout(() => {
104+
selectedChoice.parentElement.classList.remove(classToApply);
105+
getNewQuestion();
106+
}, 1000);
107+
});
109108
});
110109

111-
incrementScore = num => {
112-
score += num;
113-
scoreText.innerText = score;
110+
incrementScore = (num) => {
111+
score += num;
112+
scoreText.innerText = score;
114113
};

0 commit comments

Comments
 (0)