- Project Name
+ Guess who project
{
const start = () => {
// Here we're setting charactersInPlay array to be all the characters to start with
charactersInPlay = CHARACTERS
+ charactersInPlay.forEach((person) => {
+ board.innerHTML += `
+
+
${person.name}
+
+
+ Guess on ${person.name}?
+
+
+ `
+
+ })
// What else should happen when we start the game?
}
@@ -323,3 +335,4 @@ start()
// All the event listeners
restartButton.addEventListener('click', start)
+board.addEventListener('click', start)
From 7799429656a8d4524711e782dbc35038939b55dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9Cmikaeloling=E2=80=9D?=
<“mikael.oling@gmail.com”>
Date: Thu, 7 Sep 2023 20:46:30 +0300
Subject: [PATCH 02/14] testing
---
code/script.js | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/code/script.js b/code/script.js
index e14357dc..3ffd73a0 100644
--- a/code/script.js
+++ b/code/script.js
@@ -227,21 +227,22 @@ const setSecret = () => {
secret = charactersInPlay[Math.floor(Math.random() * charactersInPlay.length)]
}
+
// This function to start (and restart) the game
-const start = () => {
+function start () {
// Here we're setting charactersInPlay array to be all the characters to start with
charactersInPlay = CHARACTERS
charactersInPlay.forEach((person) => {
board.innerHTML += `
${person.name}
-
+
Guess on ${person.name}?
`
-
+
})
// What else should happen when we start the game?
}
@@ -318,6 +319,7 @@ const filterCharacters = (keep) => {
// when clicking guess, the player first have to confirm that they want to make a guess.
const guess = (personToConfirm) => {
// store the interaction from the player in a variable.
+ const personChecked = (`${person.name}`)
// remember the confirm() ?
// If the player wants to guess, invoke the checkMyGuess function.
}
@@ -336,3 +338,6 @@ start()
// All the event listeners
restartButton.addEventListener('click', start)
board.addEventListener('click', start)
+
+console.log('hello')
+console.log('hello')
\ No newline at end of file
From 2a684ed47d01e5d38eef4b093c6d118a67a0ee96 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9Cmikaeloling=E2=80=9D?=
<“mikael.oling@gmail.com”>
Date: Fri, 8 Sep 2023 00:19:06 +0300
Subject: [PATCH 03/14] line 279-302
---
code/script.js | 38 +++++++++++++++++++++++++++++++-------
1 file changed, 31 insertions(+), 7 deletions(-)
diff --git a/code/script.js b/code/script.js
index 3ffd73a0..6b519ad5 100644
--- a/code/script.js
+++ b/code/script.js
@@ -253,11 +253,12 @@ const selectQuestion = () => {
// This variable stores what option group (category) the question belongs to.
// We also need a variable that stores the actual value of the question we've selected.
- // const value =
+ const value = questions.options[questions.selectedIndex].value
+
currentQuestion = {
category: category,
- // value: value
+ value: value
}
}
@@ -293,16 +294,18 @@ const filterCharacters = (keep) => {
// Similar to the one above
} else {
if (keep) {
+ alert(`Yes, the person has ${person.hair} hair! Keep all people with ${person.hair} hair`)
// alert popup that says something like: "Yes, the person has yellow hair! Keep all people with yellow hair"
} else {
+ alert(`No, the person doesnt have ${person.hair} hair! Remove all people with ${person.hair} hair`)
// alert popup that says something like: "No, the person doesnt have yellow hair! Remove all people with yellow hair"
}
}
// Determine what is the category
// filter by category to keep or remove based on the keep variable.
- /*
- for hair and eyes :
+
+ /* for 'hair' and 'eyes' :
charactersInPlay = charactersInPlay.filter((person) => person[attribute] === value)
or
charactersInPlay = charactersInPlay.filter((person) => person[attribute] !== value)
@@ -314,18 +317,39 @@ const filterCharacters = (keep) => {
*/
// Invoke a function to redraw the board with the remaining people.
+ generateBoard()
}
// when clicking guess, the player first have to confirm that they want to make a guess.
const guess = (personToConfirm) => {
// store the interaction from the player in a variable.
- const personChecked = (`${person.name}`)
- // remember the confirm() ?
+ const personCheck = alert(`Do you think it is` `${person.name}``?`)
+
+ confirm(personCheck);
+ { if (personCheck === true) {
+ checkMyGuess(personToConfirm)
+ } else {
+ alert(`Ok, then keep playing!`)
+ }
+ } // This function should be invoked when you click on the button 'Guess'.
// If the player wants to guess, invoke the checkMyGuess function.
}
// If you confirm, this function is invoked
const checkMyGuess = (personToCheck) => {
+ personToCheck = secret.name,
+ alert(`You guessed on ${personToCheck}!`);
+ //win or lose section should be displayed
+ const winOrLoseText = document.getElementById('winOrLoseText');
+ const winOrLoseSection = document.getElementById('winOrLoseSection');
+ winOrLoseSection.style.display = 'block';
+ board.style.display = 'none';
+ if (personToCheck === secret.name) {
+ winOrLoseText.innerHTML = `You guessed right! It was ${personToCheck}!`;
+ } else {
+ winOrLoseText.innerHTML = `You guessed wrong! It was ${secret.name}!`;
+ }
+
// 1. Check if the personToCheck is the same as the secret person's name
// 2. Set a Message to show in the win or lose section accordingly
// 3. Show the win or lose section
@@ -337,7 +361,7 @@ start()
// All the event listeners
restartButton.addEventListener('click', start)
-board.addEventListener('click', start)
+//board.addEventListener('click', start)
console.log('hello')
console.log('hello')
\ No newline at end of file
From 6c86cbe859751d19426bccd80ab235109acde170 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9Cmikaeloling=E2=80=9D?=
<“mikael.oling@gmail.com”>
Date: Fri, 8 Sep 2023 00:28:37 +0300
Subject: [PATCH 04/14] line 233, fixed so restart doesnt duplicate board
---
code/script.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/code/script.js b/code/script.js
index 6b519ad5..127a317a 100644
--- a/code/script.js
+++ b/code/script.js
@@ -230,6 +230,7 @@ const setSecret = () => {
// This function to start (and restart) the game
function start () {
+ board.innerHTML = ''
// Here we're setting charactersInPlay array to be all the characters to start with
charactersInPlay = CHARACTERS
charactersInPlay.forEach((person) => {
@@ -239,7 +240,7 @@ function start () {
Guess on ${person.name}?
-
+
`
@@ -362,6 +363,8 @@ start()
// All the event listeners
restartButton.addEventListener('click', start)
//board.addEventListener('click', start)
+guess.addEventListener('click', checkMyGuess)
+//questions.addEventListener('change', selectQuestion)
console.log('hello')
console.log('hello')
\ No newline at end of file
From 77fdb6c43dbbefa78762a613d791514ad3eb9a34 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9Cmikaeloling=E2=80=9D?=
<“mikael.oling@gmail.com”>
Date: Fri, 8 Sep 2023 00:46:49 +0300
Subject: [PATCH 05/14] edit html, added options to dropdowns
---
code/script.js | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/code/script.js b/code/script.js
index 127a317a..b7aa04cd 100644
--- a/code/script.js
+++ b/code/script.js
@@ -240,12 +240,13 @@ function start () {
Guess on ${person.name}?
-
+
`
-
})
// What else should happen when we start the game?
+ generateBoard()
+ setSecret()
}
// setting the currentQuestion object when you select something in the dropdown
@@ -306,7 +307,7 @@ const filterCharacters = (keep) => {
// Determine what is the category
// filter by category to keep or remove based on the keep variable.
- /* for 'hair' and 'eyes' :
+ for hair and eyes :
charactersInPlay = charactersInPlay.filter((person) => person[attribute] === value)
or
charactersInPlay = charactersInPlay.filter((person) => person[attribute] !== value)
@@ -315,10 +316,11 @@ const filterCharacters = (keep) => {
charactersInPlay = charactersInPlay.filter((person) => person[category].includes(value))
or
charactersInPlay = charactersInPlay.filter((person) => !person[category].includes(value))
- */
+
// Invoke a function to redraw the board with the remaining people.
generateBoard()
+
}
// when clicking guess, the player first have to confirm that they want to make a guess.
@@ -364,6 +366,8 @@ start()
restartButton.addEventListener('click', start)
//board.addEventListener('click', start)
guess.addEventListener('click', checkMyGuess)
+//add eventlistener to Guess button
+guess.addEventListener('click', guess)
//questions.addEventListener('change', selectQuestion)
console.log('hello')
From cab52cb2c4558b74c4d2d37e66238977ab66df98 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9Cmikaeloling=E2=80=9D?=
<“mikael.oling@gmail.com”>
Date: Fri, 8 Sep 2023 01:05:32 +0300
Subject: [PATCH 06/14] line 337
---
code/index.html | 11 +++++++++++
code/script.js | 30 +++++++++++++++++++-----------
2 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/code/index.html b/code/index.html
index 32f14e7a..681eca3a 100644
--- a/code/index.html
+++ b/code/index.html
@@ -26,14 +26,25 @@
Does the person have
From 88fe915c84fa01a2213789e5a19561928a7758d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9Cmikaeloling=E2=80=9D?=
<“mikael.oling@gmail.com”>
Date: Sat, 9 Sep 2023 18:29:34 +0300
Subject: [PATCH 09/14] made the code work until play again
---
code/index.html | 2 +-
code/script.js | 234 +++++++++++++++++++++---------------------------
2 files changed, 104 insertions(+), 132 deletions(-)
diff --git a/code/index.html b/code/index.html
index d0ac3d97..62a3e72d 100644
--- a/code/index.html
+++ b/code/index.html
@@ -12,7 +12,7 @@