From 441c4c475d3beb3818d9691e45608f65527c3ce4 Mon Sep 17 00:00:00 2001 From: Othamae Date: Tue, 20 Jun 2023 12:42:47 +0200 Subject: [PATCH 1/8] Reto 25 --- .gitignore | 1 + package-lock.json | 17 +++++++++++++++++ package.json | 5 +++++ 3 files changed, 23 insertions(+) create mode 100644 .gitignore create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..30bc162798 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/node_modules \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000000..d996825bf7 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,17 @@ +{ + "name": "retos-programacion-2023", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "readline": "^1.3.0" + } + }, + "node_modules/readline": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz", + "integrity": "sha512-k2d6ACCkiNYz222Fs/iNze30rRJ1iIicW7JuX/7/cozvih6YCkFZH+J6mAFDVgv0dRBaAyr4jDqC95R2y4IADg==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000000..b8c2fea423 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "readline": "^1.3.0" + } +} From 687e9d686805e58a080acfc017bfee74321497b6 Mon Sep 17 00:00:00 2001 From: Othamae Date: Wed, 28 Jun 2023 23:25:47 +0200 Subject: [PATCH 2/8] Reto #13 - javascript --- .../javascript/othamae.js | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 Retos/Reto #13 - ADIVINA LA PALABRA [Media]/javascript/othamae.js diff --git a/Retos/Reto #13 - ADIVINA LA PALABRA [Media]/javascript/othamae.js b/Retos/Reto #13 - ADIVINA LA PALABRA [Media]/javascript/othamae.js new file mode 100644 index 0000000000..39c5a23a26 --- /dev/null +++ b/Retos/Reto #13 - ADIVINA LA PALABRA [Media]/javascript/othamae.js @@ -0,0 +1,107 @@ +/* + * Crea un pequeño juego que consista en adivinar palabras en un número máximo de intentos: + * - El juego comienza proponiendo una palabra aleatoria incompleta + * - Por ejemplo "m_ur_d_v", y el número de intentos que le quedan + * - El usuario puede introducir únicamente una letra o una palabra (de la misma longitud que + * la palabra a adivinar) + * - Si escribe una letra y acierta, se muestra esa letra en la palabra. Si falla, se resta + * uno al número de intentos + * - Si escribe una resolución y acierta, finaliza el juego, en caso contrario, se resta uno + * al número de intentos + * - Si el contador de intentos llega a 0, el jugador pierde + * - La palabra debe ocultar de forma aleatoria letras, y nunca puede comenzar ocultando más del 60% + * - Puedes utilizar las palabras que quieras y el número de intentos que consideres + */ + +const readline = require('readline') + + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + + }) + + +const hideWord = (word) => { + let hiddenWord = word.split(''); + let num = Math.floor(word.length * 0.6) + while (num >0) { + const randomIndex = Math.floor(Math.random() * word.length) + let letter = hiddenWord[randomIndex] + if (letter !== '_') { + for(let i = 0; i < word.length; i++){ + if(word[i] === letter){ + hiddenWord[i] = '_' + } + } + } + num-- + } + return hiddenWord.join('') +} + +const wordFound = (wordToCheck, word) => { + let wordToCheckString = wordToCheck.join('') + if (wordToCheckString === word) { + console.log('You win!') + rl.close() + return true + } + return false +} + +const letterFound = (letter, word) => { + return word.includes(letter) +} +const openLetter = (userGuess, word, hiddenWord) => { + let newHiddenWord = hiddenWord.split('') + const wordArray = word.split('') + if (word.includes(userGuess[0])) { + for (let i = 0; i < word.length; i++) { + if (wordArray[i] === userGuess[0]) { + newHiddenWord[i] = userGuess[0] + } + } + } + return newHiddenWord.join('') + +} + +const guessWord = (word, attempts) => { + console.log('Try to guess the word, you have ' + attempts + ' attempts') + let hiddenWord = hideWord(word) + console.log('The word is: ' + hiddenWord) + rl.on('line', (input) => { + let userInput = input.trim() + let userGuess = userInput.split('') + if((userGuess.length > 1 && userGuess.length != word.length) || userInput=== ''){ + console.log('You must write a word or a letter') + } else if(userGuess.length === 1){ + letterFound(userGuess[0], word) ? hiddenWord = openLetter(userGuess, word, hiddenWord) : attempts-- + wordFound(hiddenWord.split(''), word) ? `Word found!! ${word}` : console.log('Try again, you have ' + attempts + ' attempts') + } + if (userGuess.length === word.length ) { + wordFound(userGuess, word) ? `Word found!! ${word}` : attempts-- + } + + if (attempts === 0) { + console.log('No more attempts, you lose 😢') + rl.close() + } else { + console.log('The word is: ' + hiddenWord) + } + + + }) + + +} + + +const playGame = (word, attempts) => { + guessWord(word, attempts) +} + + +playGame("holacaracola", 5) \ No newline at end of file From bab61fd343d993e7273b26c5449a05b3d88e05a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ver=C3=B3nica=20Conesa?= <90536006+Othamae@users.noreply.github.com> Date: Wed, 28 Jun 2023 23:32:06 +0200 Subject: [PATCH 3/8] Delete package.json --- package.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 package.json diff --git a/package.json b/package.json deleted file mode 100644 index b8c2fea423..0000000000 --- a/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dependencies": { - "readline": "^1.3.0" - } -} From 7e4e319f40969ebd444db000324f23805f8d8f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ver=C3=B3nica=20Conesa?= <90536006+Othamae@users.noreply.github.com> Date: Wed, 28 Jun 2023 23:32:26 +0200 Subject: [PATCH 4/8] Delete package-lock.json --- package-lock.json | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index d996825bf7..0000000000 --- a/package-lock.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "retos-programacion-2023", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "dependencies": { - "readline": "^1.3.0" - } - }, - "node_modules/readline": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz", - "integrity": "sha512-k2d6ACCkiNYz222Fs/iNze30rRJ1iIicW7JuX/7/cozvih6YCkFZH+J6mAFDVgv0dRBaAyr4jDqC95R2y4IADg==" - } - } -} From fd7be77d73afa41162cdb8fcd855ba10b4b1b89e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ver=C3=B3nica=20Conesa?= <90536006+Othamae@users.noreply.github.com> Date: Wed, 28 Jun 2023 23:32:47 +0200 Subject: [PATCH 5/8] Delete .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 30bc162798..0000000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/node_modules \ No newline at end of file From d8d2b8114edf5edbc52ec2c82d47a45751445392 Mon Sep 17 00:00:00 2001 From: Othamae Date: Wed, 28 Jun 2023 23:46:25 +0200 Subject: [PATCH 6/8] Reto #12 - javascript --- .../javascript/othamae.js" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "Retos/Reto #12 - VIERNES 13 [F\303\241cil]/javascript/othamae.js" diff --git "a/Retos/Reto #12 - VIERNES 13 [F\303\241cil]/javascript/othamae.js" "b/Retos/Reto #12 - VIERNES 13 [F\303\241cil]/javascript/othamae.js" new file mode 100644 index 0000000000..e415b2491e --- /dev/null +++ "b/Retos/Reto #12 - VIERNES 13 [F\303\241cil]/javascript/othamae.js" @@ -0,0 +1,15 @@ +/* + * Crea una función que sea capaz de detectar si existe un viernes 13 en el mes y el año indicados. + * - La función recibirá el mes y el año y retornará verdadero o falso. + */ + +const isFriday13th = (month, year) => { + const date = new Date(year, month - 1, 13); + return date.getDay() === 5; +} + +console.log(isFriday13th(5, 2020)); +console.log(isFriday13th(10, 2021)); +console.log(isFriday13th(5, 2022)); +console.log(isFriday13th(7, 2023)); +console.log(isFriday13th(6, 2024)); From 703f8a24bdc3d1f712bfe8f17a416d8213f4dcaf Mon Sep 17 00:00:00 2001 From: Othamae Date: Wed, 28 Jun 2023 23:51:19 +0200 Subject: [PATCH 7/8] Reto #12 - javascript --- .../javascript/othamae.js" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "Retos/Reto #12 - VIERNES 13 [F\303\241cil]/javascript/othamae.js" diff --git "a/Retos/Reto #12 - VIERNES 13 [F\303\241cil]/javascript/othamae.js" "b/Retos/Reto #12 - VIERNES 13 [F\303\241cil]/javascript/othamae.js" new file mode 100644 index 0000000000..e415b2491e --- /dev/null +++ "b/Retos/Reto #12 - VIERNES 13 [F\303\241cil]/javascript/othamae.js" @@ -0,0 +1,15 @@ +/* + * Crea una función que sea capaz de detectar si existe un viernes 13 en el mes y el año indicados. + * - La función recibirá el mes y el año y retornará verdadero o falso. + */ + +const isFriday13th = (month, year) => { + const date = new Date(year, month - 1, 13); + return date.getDay() === 5; +} + +console.log(isFriday13th(5, 2020)); +console.log(isFriday13th(10, 2021)); +console.log(isFriday13th(5, 2022)); +console.log(isFriday13th(7, 2023)); +console.log(isFriday13th(6, 2024)); From 8d2e5791277acee931e46a37f5110813c30a58a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ver=C3=B3nica=20Conesa?= <90536006+Othamae@users.noreply.github.com> Date: Wed, 28 Jun 2023 23:53:13 +0200 Subject: [PATCH 8/8] Delete othamae.js --- .../javascript/othamae.js" | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 "Retos/Reto #12 - VIERNES 13 [F\303\241cil]/javascript/othamae.js" diff --git "a/Retos/Reto #12 - VIERNES 13 [F\303\241cil]/javascript/othamae.js" "b/Retos/Reto #12 - VIERNES 13 [F\303\241cil]/javascript/othamae.js" deleted file mode 100644 index e415b2491e..0000000000 --- "a/Retos/Reto #12 - VIERNES 13 [F\303\241cil]/javascript/othamae.js" +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Crea una función que sea capaz de detectar si existe un viernes 13 en el mes y el año indicados. - * - La función recibirá el mes y el año y retornará verdadero o falso. - */ - -const isFriday13th = (month, year) => { - const date = new Date(year, month - 1, 13); - return date.getDay() === 5; -} - -console.log(isFriday13th(5, 2020)); -console.log(isFriday13th(10, 2021)); -console.log(isFriday13th(5, 2022)); -console.log(isFriday13th(7, 2023)); -console.log(isFriday13th(6, 2024));