diff --git a/_small_exercices/looping_through_arrays.js b/_small_exercices/looping_through_arrays.js new file mode 100644 index 0000000..7f9b4b4 --- /dev/null +++ b/_small_exercices/looping_through_arrays.js @@ -0,0 +1,26 @@ +const vacationSpots = ['Bali', 'Paris', 'Tulum']; +const bestVacationSpots = ["Pyongyang", "Caracas", "Beijing", "Havana", "Ho-Chi-Minh ville"]; + +// Write your code below + +for (let i = 0; i < vacationSpots.length; i++) { + console.log(`I would love to visit ${vacationSpots[i]}`); +} + +console.log("----------"); + +for (const city of vacationSpots) { + console.log(`I would love to visit ${city}`); +} + +console.log("----------"); + +function cityTravelling(array) { + for (const item of array) { + console.log(`I would love to visit ${item}`); + } +} + +cityTravelling(vacationSpots); +console.log("----------"); +cityTravelling(bestVacationSpots); \ No newline at end of file diff --git a/_small_exercices/whale_talk.js b/_small_exercices/whale_talk.js new file mode 100644 index 0000000..fc78d6b --- /dev/null +++ b/_small_exercices/whale_talk.js @@ -0,0 +1,24 @@ +const input = "Il existe une humilite naive, assez frequente en somme, qui, lorsqu’on la possede, vous rend, une fois pour toutes, impropre a etre disciple de la connaissance. Car, au moment ou un homme de cette espece aperçoit quelque chose qui le frappe, il se retourne en quelque sorte sur lui-meme et se dit : « Tu t’es trompe ! Ou avais-tu tes sens ! Cela ne peut pas etre la verite ! » — Et alors, au lieu d’y regarder encore une fois de plus pres, au lieu de preter encore l’oreille, il s’enfuit intimide et evite de rencontrer la chose frappante qu’il cherche a se sortir de la tete aussi vite que possible. Son canon interieur dit : « Je ne veux rien voir qui soit en contradiction avec l’opinion courante sur les choses ! Suis-je fait, moi, pour decouvrir des verites nouvelles ? Il y en a deja trop d’anciennes. » "; + +const inputLowercase = input.toLowerCase(); + +const vowels = ["a", "e", "i", "o", "u"]; + +const resultArray = []; + +for (const char of inputLowercase) { + //console.log(char); + for (const vowel of vowels) { + //console.log(vowel); + if (vowel === char) { + if (vowel === "e" || vowel === "u") { + resultArray.push(vowel); // Add an additionnal E or U if present on top of the other .push + } + resultArray.push(vowel); // Add a push() for every vowel, whatever it is + } + } +} + +const formatedResultArray = resultArray.join("").toUpperCase(); + +console.log(formatedResultArray); \ No newline at end of file diff --git a/number-guesser-starting.zip b/number-guesser-starting.zip new file mode 100644 index 0000000..220526b Binary files /dev/null and b/number-guesser-starting.zip differ diff --git a/number-guesser-starting/game.js b/number-guesser-starting/game.js new file mode 100644 index 0000000..fa0c6c3 --- /dev/null +++ b/number-guesser-starting/game.js @@ -0,0 +1,99 @@ +let target; + +const humanGuessInput = document.getElementById('human-guess'); + +const roundNumberDisplay = document.getElementById('round-number'); + +const computerGuessDisplay = document.getElementById('computer-guess'); +const humanScoreDisplay = document.getElementById('human-score'); +const computerScoreDisplay = document.getElementById('computer-score'); +const targetNumberDisplay = document.getElementById('target-number'); +const computerWinsDisplay = document.getElementById('computer-wins'); + +const guessButton = document.getElementById('guess'); +const nextRoundButton = document.getElementById('next-round') + +guessButton.addEventListener('click', () => { + // Generate the target value + target = generateTarget(); + // Retrieve the player's guess + const currentHumanGuess = humanGuessInput.value; + // Make a random 'computer guess' + const computerGuess = Math.floor(Math.random() * 10); + + // Display the computer guess and the target + computerGuessDisplay.innerText = computerGuess; + targetNumberDisplay.innerText = target; + + // Determine if the human or computer wins: + const humanIsWinner = compareGuesses(currentHumanGuess, computerGuess, target) + const winner = humanIsWinner ? 'human' : 'computer' + + // Update the correct score: + updateScore(winner); + + // Display the winner + if (humanIsWinner) { + guessButton.innerText = 'You Win!!!!!'; + guessButton.classList.toggle('winning-text') + } else { + computerWinsDisplay.innerText = 'Computer Wins!!!'; + } + + // winnerDisplay.innerText = humanIsWinner ? 'You win!' : 'Computer wins!'; + + // Display the current scores: + humanScoreDisplay.innerText = humanScore; + computerScoreDisplay.innerText = computerScore; + + // Set the correct disabled state for the buttons + guessButton.setAttribute('disabled', true) + nextRoundButton.removeAttribute('disabled'); +}); + +nextRoundButton.addEventListener('click', () => { + // Increase the round number + advanceRound(); + // Display the new round number + roundNumberDisplay.innerText = currentRoundNumber; + + // Set the correct disabled state for the buttons + nextRoundButton.setAttribute('disabled', true); + guessButton.removeAttribute('disabled'); + + // Reset the guess input box and the target number display: + targetNumberDisplay.innerText = '?'; + guessButton.innerText = 'Make a Guess'; + humanGuessInput.value = ''; + computerGuessDisplay.innerText = '?'; + computerWinsDisplay.innerText = ''; + guessButton.classList.remove('winning-text'); +}); + +const addButton = document.getElementById('add'); +const subtractButton = document.getElementById('subtract'); + +addButton.addEventListener('click', () => { + humanGuessInput.value = +humanGuessInput.value + 1; + handleValueChange(humanGuessInput.value); +}); + +subtractButton.addEventListener('click', () => { + humanGuessInput.value = +humanGuessInput.value - 1; + handleValueChange(humanGuessInput.value); +}); + +const handleValueChange = value => { + if (value > 0 && value <= 9) { + subtractButton.removeAttribute('disabled'); + addButton.removeAttribute('disabled'); + } else if (value > 9) { + addButton.setAttribute('disabled', true); + } else if (value <= 0) { + subtractButton.setAttribute('disabled', true); + } +} + +humanGuessInput.addEventListener('input', function(e) { + handleValueChange(e.target.value); +}); diff --git a/number-guesser-starting/index.html b/number-guesser-starting/index.html new file mode 100644 index 0000000..690142a --- /dev/null +++ b/number-guesser-starting/index.html @@ -0,0 +1,67 @@ + + + +
+Round 1
+Target Number: ?
+Computer
+Score: 0
+?
+ +You
+Score: 0
+Input a number between 0 and 9
+Click "Make a Guess" to submit your guess and see who won the round.
+Click "Next Round" to play again.
+