From 09e5452a8d9b5909d5edb38505f1333428b6223d Mon Sep 17 00:00:00 2001 From: Marco-Tranaso Date: Mon, 17 Mar 2025 17:38:38 +0100 Subject: [PATCH 1/3] aggiunta esercizio impiccato --- hangman.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 hangman.js diff --git a/hangman.js b/hangman.js new file mode 100644 index 0000000..06f8ba9 --- /dev/null +++ b/hangman.js @@ -0,0 +1,35 @@ +let array1 = ['C', 'A', 'T']; +let array2 = ['_', '_', '_']; +let max_guess = 6; +let reward = 0 +function guessLetter(letter) { + let check = array1.includes(letter); + if (check) { + for (let i = 0; i < array1.length; i++) { + if (array1[i] == letter) { + array2[i] = letter; + } + } + console.log(array2) + reward+=100; + console.log(`You guessed the letter Balance ${reward} points`) + if (array2.includes('_') == false) { + console.log("You won") + } + } + else { + max_guess--; + console.log(array2) + reward-=50; + console.log(`You didn't guess the letter Balance ${reward} points`) + console.log(`Guesses left: ${max_guess}`) + if (max_guess <= 0) { + console.log("You lost") + } + + } + +} +guessLetter("C") +guessLetter("A") +guessLetter("T") \ No newline at end of file From 31487f78b2e2282d9a959b98fddecfdda849c301 Mon Sep 17 00:00:00 2001 From: Marco-Tranaso Date: Mon, 17 Mar 2025 17:42:58 +0100 Subject: [PATCH 2/3] aggiunta esercizio impiccato --- hangman.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/hangman.js b/hangman.js index 06f8ba9..cec891c 100644 --- a/hangman.js +++ b/hangman.js @@ -1,3 +1,33 @@ +/* +Word Guesser + +● Create two arrays: + ○ one for the letters of the word (e.g. 'C', 'A', 'T') + ○ Another for the current guessed letters (start with '_', '_', '_' and add the correct letters to it). + +● Write a function called guessLetter that should: + ○ Take one parameter, a letter. + ○ Have a maximum number of guesses (e.g. 6). + ○ Check if the letter is in the word array. + ○ If the letter matches, add it in the correct position of the guessed array. + ○ Show the user the current guessed letters. + ○ Tell the user if they guessed a correct letter. + ○ Tell the user how many guesses remain. + ○ Tell the user if they won or lost the game. + +Call your function to make guesses: + guessLetter('G'); + guessLetter('I'); + guessLetter('O'); + guessLetter('A'); + guessLetter('T'); + +● Bonus: + ○ Add a reward for correct guesses and subtract an amount for failed guesses. + ○ Show the user the total reward (positive or negative). +*/ + + let array1 = ['C', 'A', 'T']; let array2 = ['_', '_', '_']; let max_guess = 6; From e5b6bf41a56bccf6fef8ac816d162ebfbe596f1c Mon Sep 17 00:00:00 2001 From: Marco-Tranaso Date: Mon, 17 Mar 2025 17:46:19 +0100 Subject: [PATCH 3/3] aggiunta esercizio impiccato --- hangman.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/hangman.js b/hangman.js index cec891c..07f0620 100644 --- a/hangman.js +++ b/hangman.js @@ -31,7 +31,7 @@ Call your function to make guesses: let array1 = ['C', 'A', 'T']; let array2 = ['_', '_', '_']; let max_guess = 6; -let reward = 0 +let reward = 0; function guessLetter(letter) { let check = array1.includes(letter); if (check) { @@ -40,26 +40,26 @@ function guessLetter(letter) { array2[i] = letter; } } - console.log(array2) + console.log(array2); reward+=100; - console.log(`You guessed the letter Balance ${reward} points`) + console.log(`You guessed the letter Balance ${reward} points`); if (array2.includes('_') == false) { - console.log("You won") + console.log("You won"); } } else { max_guess--; - console.log(array2) + console.log(array2); reward-=50; - console.log(`You didn't guess the letter Balance ${reward} points`) - console.log(`Guesses left: ${max_guess}`) + console.log(`You didn't guess the letter Balance ${reward} points`); + console.log(`Guesses left: ${max_guess}`); if (max_guess <= 0) { - console.log("You lost") + console.log("You lost"); } } } -guessLetter("C") -guessLetter("A") -guessLetter("T") \ No newline at end of file +guessLetter("C"); +guessLetter("A"); +guessLetter("T"); \ No newline at end of file