From 16840e8e82459a356c68d696b4eb2374238cf388 Mon Sep 17 00:00:00 2001 From: gauvainboiche Date: Wed, 9 Jul 2025 10:41:01 +0200 Subject: [PATCH] Exercices adding --- _small_exercices/looping_through_arrays.js | 26 +++ _small_exercices/whale_talk.js | 24 +++ number-guesser-starting.zip | Bin 0 -> 2987 bytes number-guesser-starting/game.js | 99 +++++++++++ number-guesser-starting/index.html | 67 +++++++ number-guesser-starting/script.js | 34 ++++ number-guesser-starting/style.css | 195 +++++++++++++++++++++ 7 files changed, 445 insertions(+) create mode 100644 _small_exercices/looping_through_arrays.js create mode 100644 _small_exercices/whale_talk.js create mode 100644 number-guesser-starting.zip create mode 100644 number-guesser-starting/game.js create mode 100644 number-guesser-starting/index.html create mode 100644 number-guesser-starting/script.js create mode 100644 number-guesser-starting/style.css 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 0000000000000000000000000000000000000000..220526bc68b2a21d7ff5a0ff67359694a7c03826 GIT binary patch literal 2987 zcmZ9Oc{r5a8^<5}WT$MEY+167wd_kJ`#M8W;b)ye$O!RfCwmy#Wf^N^o3T%_7s4d6 z(_*Ysma!K7#=G?DJ?FZw>-_aS=XtLC^Zni?`V^FB01#=z{JV{S6N?652Au8O9VOx3 z(3|wYhtqqv$4IqJb_T#$7#g3GX2vdB(sMj8*U9TmriO?VBePJ`=iKQZ3HOaUsM7rx1QpzNg zuU*m{tv+NU?8OO2fE&j1Y*4+VrLS+xBja>wAM*6-jyvb!>c8It6j)gmk*dI+L}%`xJT=e zacQG_di;@lB6^r?S7B-QAqH`kr8iB#;}2uBW^~N8VqGHVd9CrNjY~h4$dT& zZdb|MWqiv2HYwpSs29AOr+mbmY?6T0EM&dieAAUhvGmSc%5`nLUQ&$50{ZkFS7KE5 zkoVo#8vudi5Zz$)w+L?;iXSr;&1rp{Z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^ONY1G#+c5pnNZ36~i&E-dv}JsqE{=0}be`*yCsWb^WOo)ABfYQne)8uI0A2;t+c zB^|Ps`#U(cBanK&9F3iOzLuL@OIh$(CqEW02vSazr1^UPMu2)g zc4|Ors^!_~H_Nt^?x#L48$8FabfA1aE`>K+87j?~%b%T;o%9M(jkSMutq4k}-+Nm$ zB`gS1^H--*8}uykC%oGo+RV&mQP)0d$Z2Y94w9X*RhJNd$02vnRIS7t{{S~Q z7x%4=?3k)@ag*mvq%7N{J*J9`oQ>k&S@dMi(Ey~d`)g^SLXHo=CR5O_$@HYaaU7mB z6WZSdUXrdn8IGV|;doNx*mh20f9f}lOlshy34wrrOz5P { + // 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 @@ + + + + + Number Guesser + + + + +
+
+

Number Guesser!

+
+ +
+

Round 1

+

Target Number: ?

+
+ +
+
+
+

Computer

+

Score: 0

+
+

?

+

+
+
+
+

You

+

Score: 0

+
+ +
+ + +
+ +
+
+ +
+ +
+ +
+ +
+
+

Step 1

+

Input a number between 0 and 9

+
+
+

Step 2

+

Click "Make a Guess" to submit your guess and see who won the round.

+
+
+

Step 3

+

Click "Next Round" to play again.

+
+
+ + + + + \ No newline at end of file diff --git a/number-guesser-starting/script.js b/number-guesser-starting/script.js new file mode 100644 index 0000000..351d8da --- /dev/null +++ b/number-guesser-starting/script.js @@ -0,0 +1,34 @@ +let humanScore = 0; +let computerScore = 0; +let currentRoundNumber = 1; + +// Write your code below: + +function generateTarget() { + return Math.floor(Math.random() * 10); +} + +function compareGuesses(humanGuess, computerGuess, target) { + if (humanGuess < 0 || humanGuess > 9) { + alert("Your guess must be between 0 and 9."); + return false; + } + + const humanDiff = Math.abs(target - humanGuess); + const computerDiff = Math.abs(target - computerGuess); + + return humanDiff <= computerDiff; +} + +function updateScore(winner) { + if (winner === 'human') { + humanScore++; + } else if (winner === 'computer') { + computerScore++; + } +} + +function advanceRound() { + currentRoundNumber++; + console.log(`Current Round: ${currentRoundNumber}`); +} \ No newline at end of file diff --git a/number-guesser-starting/style.css b/number-guesser-starting/style.css new file mode 100644 index 0000000..f0cdadf --- /dev/null +++ b/number-guesser-starting/style.css @@ -0,0 +1,195 @@ +* { + font-family: 'Nunito Sans'; + box-sizing: border-box; +} + +body { + margin: 0 auto; + padding: 3px; + background-color: #fff; +} + +.game-container { + max-width: 640px; + margin: 0 auto; + text-align: center; +} + +header { + display: flex; + justify-content: center +} + +.rounds { + display: flex; + flex-direction: column; + align-items: center; + margin-bottom: 30px; +} + +.round-label { + font-size: 30px; + font-weight: 700; + margin-bottom: 0px; +} + +.guess { + min-width: 303px; + height: 328px; + display: flex; + flex-direction: column; + align-items: center; + padding: 19px; +} + +.guessing-area { + display: flex; + justify-content: space-around; + align-items: flex-start; + margin-bottom: 60px; +} + +.guess-title { + display: flex; + flex-direction: column; + align-items: center; + justify-content: flex-start; + margin-bottom: 20px; +} + +.guess-label { + font-size: 18px; + font-weight: 700; + margin: 0; +} + +.score-label { + font-size: 14px; + font-weight: 700; + margin: 0; +} + +.target-guess { + display: flex; + flex-direction: column; + align-items: center; + justify-content: flex-start; +} + +.computer-guess { + background-color: #ececec; +} + +#computer-guess { + font-size: 50px; + font-weight: 700; + color: #a5a5a5; +} + +.human-guess { + border: 1px solid #979797; +} + +.guess input { + height: 90px; + width: 90px; + font-size: 30px; + text-align: center; + margin: 0 auto; + margin-bottom: 7px; +} + +.number-controls { + font-size: 0; + margin-bottom: 23px; +} + +.number-control { + border: solid 1px #4c7ef3; + display: inline-block; + width: 45px; + height: 35px; + font-size: 24px; + font-weight: 700; + color: #4c7ef3; + cursor: pointer; +} + +.number-controls button[disabled] { + color: #dfdfdf; + cursor: default; +} + +.left { + border-top-left-radius: 22.5px; + border-bottom-left-radius: 22.5px; +} + +.right { + border-top-right-radius: 22.5px; + border-bottom-right-radius: 22.5px; + border-left-width: 0px; +} + +.controls { + display: flex; + justify-content: space-around; +} + +.button { + background-color: #4c7ef3; + color: #fff; + cursor: pointer; +} + +#guess { + padding: 20px; + width: 169px; + height: 59px; + border: none; + font-weight: 700; + font-size: 14px; +} + +input[type=number]::-webkit-inner-spin-button { + -webkit-appearance: none; +} + +#next-round { + width: 179px; + height: 64px; + font-size: 18px; + font-weight: bold; + margin-left: auto; + margin-right: auto; + margin-bottom: 60px; +} + +.button[disabled] { + background-color: #d2d2d2; + color: #a0a0a0; + cursor: default; +} + +.instructions { + background-color: #ececec; + width: 100%; + display: flex; + justify-content: space-around; +} + +.instruction { + width: 180px; + padding: 2px; + text-align: center; +} + +.instructions h3 { + font-size: 14px; +} + + +.winning-text, .winning-text[disabled] { + color: #ec3636; + font-weight: 700; +} \ No newline at end of file