From cd910d33d2dda280dc8a2217194ddf9c862a18b9 Mon Sep 17 00:00:00 2001
From: Harold Wolfinger
Date: Thu, 16 Aug 2018 14:28:51 -0400
Subject: [PATCH 1/2] beginnings of the topicChoice function
---
index.html | 10 +++++++
main.js | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 89 insertions(+), 4 deletions(-)
diff --git a/index.html b/index.html
index 7bb8216..74994e8 100644
--- a/index.html
+++ b/index.html
@@ -8,6 +8,16 @@
+
Topic Areas
+
Please select the topics you are interested in being quizzed on below
+
+
Functions
+
Loops
+
Objects
+
The DOM
+
Local Storage
+
+
Coding Quiz
diff --git a/main.js b/main.js
index b56900e..fcc1119 100644
--- a/main.js
+++ b/main.js
@@ -1,5 +1,6 @@
//=============GLOBAL VARIABLES DECLARATION & ASSIGNMENT============
//creating an array that stores the questions for the topic 'functions'
+let testBank = [];
let quizBank= [];
//counts the number of questions we ask, starting at zero for an array
let counter = 0;
@@ -21,6 +22,14 @@ let quizElement = document.getElementById('quiz');
let buttonHolder = document.getElementById('buttonHolder');
let questionButton= document.createElement('button');
+//===TOPIC SELECTOR==
+
+let elTopic1 = document.getElementById('functions')
+let elTopic2 = document.getElementById('loops')
+let elTopic3 = document.getElementById('objects')
+let elTopic4 = document.getElementById('DOM')
+let elTopic5 = document.getElementById('localStorage')
+
//===========OBJECT CONSTRUCTOR & INSTANCES============
//creating an object constructor with properties and method for the questions
@@ -69,7 +78,76 @@ q34 = new Question('DOM', 'Methods that find elements in the DOM are called what
q35 = new Question('DOM', 'A collection of nodes is known as a _______?', ['nodeList', 'nodeArray', 'nodeQuery', 'nodeScript'], null, null) ;
//pushing the questions of the function questions objects into an array that holds all the questions for the function topic
-quizBank.push(q01, q02, q03, q04, q05, q11, q12, q21, q22, q23, q31, q32, q33, q34, q35);
+testBank.push(q01, q02, q03, q04, q05, q11, q12, q21, q22, q23, q31, q32, q33, q34, q35);
+
+// then attach an event handler
+let topicChoice1 = function(e) {
+ for (z = 0; z < testBank.length; z++) {
+ if (document.getElementById('functions').id === testBank[z].topic['functions']) {
+ quizBank.push(testBank[z])
+ console.log(quizBank)
+ }
+ }
+
+ questionPopulate();
+ answerChoices();
+ answerEventFunc();
+}
+
+let topicChoice2 = function(e) {
+ for (z = 0; z < testBank.length; z++) {
+ if (document.getElementById('loops').id === testBank[z].topic['loops']) {
+ quizBank.push(testBank[z])
+ }
+ }
+
+ questionPopulate();
+ answerChoices();
+ answerEventFunc();
+}
+
+let topicChoice3 = function(e) {
+ for (z = 0; z < testBank.length; z++) {
+ if (document.getElementById('objects').id === testBank[z].topic['objects']) {
+ quizBank.push(testBank[z])
+ }
+ }
+
+ questionPopulate();
+ answerChoices();
+ answerEventFunc();
+}
+
+let topicChoice4 = function(e) {
+ for (z = 0; z < testBank.length; z++) {
+ if (document.getElementById('DOM').id === testBank[z].topic['DOM']) {
+ quizBank.push(testBank[z])
+ }
+ }
+
+ questionPopulate();
+ answerChoices();
+ answerEventFunc();
+}
+
+let topicChoice5 = function(e) {
+ for (z = 0; z < testBank.length; z++) {
+ if (document.getElementById('localStorage').id === testBank[z].topic['localStorage']) {
+ quizBank.push(testBank[z])
+ }
+ }
+
+ questionPopulate();
+ answerChoices();
+ answerEventFunc();
+}
+
+// then attach an event listener
+elTopic1.addEventListener('click', topicChoice1) ;
+elTopic2.addEventListener('click', topicChoice2) ;
+elTopic3.addEventListener('click', topicChoice3) ;
+elTopic4.addEventListener('click', topicChoice4) ;
+elTopic5.addEventListener('click', topicChoice5) ;
//=========Index for tracking what questions we are on===============
@@ -180,6 +258,3 @@ let removeEventFunc = function() {
questionButton.addEventListener('click', nextClicked)
-questionPopulate();
-answerChoices();
-answerEventFunc();
\ No newline at end of file
From 287c4caa8fccb46f9a1306b7648558d7087e2e05 Mon Sep 17 00:00:00 2001
From: Harold Wolfinger
Date: Thu, 16 Aug 2018 18:06:16 -0400
Subject: [PATCH 2/2] initial populating of questions by topicChoice working,
but there are bugs (particularly if you slect more than one topic, or if you
click on a topic area after you start doing questions from one other topic)
---
main.js | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/main.js b/main.js
index fcc1119..4acf920 100644
--- a/main.js
+++ b/main.js
@@ -83,7 +83,7 @@ testBank.push(q01, q02, q03, q04, q05, q11, q12, q21, q22, q23, q31, q32, q33, q
// then attach an event handler
let topicChoice1 = function(e) {
for (z = 0; z < testBank.length; z++) {
- if (document.getElementById('functions').id === testBank[z].topic['functions']) {
+ if (document.getElementById('functions').id === testBank[z].topic) {
quizBank.push(testBank[z])
console.log(quizBank)
}
@@ -96,7 +96,7 @@ let topicChoice1 = function(e) {
let topicChoice2 = function(e) {
for (z = 0; z < testBank.length; z++) {
- if (document.getElementById('loops').id === testBank[z].topic['loops']) {
+ if (document.getElementById('loops').id === testBank[z].topic) {
quizBank.push(testBank[z])
}
}
@@ -108,7 +108,7 @@ let topicChoice2 = function(e) {
let topicChoice3 = function(e) {
for (z = 0; z < testBank.length; z++) {
- if (document.getElementById('objects').id === testBank[z].topic['objects']) {
+ if (document.getElementById('objects').id === testBank[z].topic) {
quizBank.push(testBank[z])
}
}
@@ -120,7 +120,7 @@ let topicChoice3 = function(e) {
let topicChoice4 = function(e) {
for (z = 0; z < testBank.length; z++) {
- if (document.getElementById('DOM').id === testBank[z].topic['DOM']) {
+ if (document.getElementById('DOM').id === testBank[z].topic) {
quizBank.push(testBank[z])
}
}
@@ -132,7 +132,7 @@ let topicChoice4 = function(e) {
let topicChoice5 = function(e) {
for (z = 0; z < testBank.length; z++) {
- if (document.getElementById('localStorage').id === testBank[z].topic['localStorage']) {
+ if (document.getElementById('localStorage').id === testBank[z].topic) {
quizBank.push(testBank[z])
}
}
@@ -256,5 +256,4 @@ let removeEventFunc = function() {
}
}
-questionButton.addEventListener('click', nextClicked)
-
+questionButton.addEventListener('click', nextClicked)
\ No newline at end of file