From 1fd39153422c11a2cd36fa4030b58697dd2bc73c Mon Sep 17 00:00:00 2001 From: AidaG91 Date: Tue, 17 Jun 2025 18:14:03 +0200 Subject: [PATCH 1/2] First and Second Iterations --- .vscode/settings.json | 3 +++ index.js | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..6f3a2913e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5501 +} \ No newline at end of file diff --git a/index.js b/index.js index 6b0fec3ad..0645e9c05 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,20 @@ // Iteration 1: Names and Input +let hacker1 = prompt ("Driver, what's your name?"); +let hacker2 = prompt ("Navigator, what's your name?"); + +console.log(`The driver's name is ${hacker1}.`); +console.log(`The navigator's name is ${hacker2}.`); // Iteration 2: Conditionals +if (hacker1.length > hacker2.length) { + console.log(`The driver has the longest name, it has ${hacker1.length} characters.`) +} else if (hacker1.length < hacker2.length) { +console.log(`It seems that the navigator has the longest name, it has ${hacker2.length} characters.`) +} else { +console.log(`Wow, you both have equally long names, ${hacker1.length} characters.`) +} + // Iteration 3: Loops From 07c53bec5ad99556bccff07fa6841d49e4c83e36 Mon Sep 17 00:00:00 2001 From: AidaG91 Date: Tue, 17 Jun 2025 19:08:27 +0200 Subject: [PATCH 2/2] Iteration 3 --- index.js | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 0645e9c05..c3b061ac0 100644 --- a/index.js +++ b/index.js @@ -1,20 +1,55 @@ // Iteration 1: Names and Input -let hacker1 = prompt ("Driver, what's your name?"); -let hacker2 = prompt ("Navigator, what's your name?"); +let hacker1 = prompt("Driver, what's your name?"); +let hacker2 = prompt("Navigator, what's your name?"); console.log(`The driver's name is ${hacker1}.`); console.log(`The navigator's name is ${hacker2}.`); - // Iteration 2: Conditionals if (hacker1.length > hacker2.length) { - console.log(`The driver has the longest name, it has ${hacker1.length} characters.`) + console.log( + `The driver has the longest name, it has ${hacker1.length} characters.` + ); } else if (hacker1.length < hacker2.length) { -console.log(`It seems that the navigator has the longest name, it has ${hacker2.length} characters.`) + console.log( + `It seems that the navigator has the longest name, it has ${hacker2.length} characters.` + ); } else { -console.log(`Wow, you both have equally long names, ${hacker1.length} characters.`) + console.log( + `Wow, you both have equally long names, ${hacker1.length} characters.` + ); } - // Iteration 3: Loops + +// Iteration 3.1 + +let driverNameSpaced = ""; + +for (let i = 0; i < hacker1.length; i++) { + let char = hacker1[i]; + let upperChar = char.toUpperCase(); + driverNameSpaced = driverNameSpaced + upperChar + " "; +} + +driverNameSpaced = driverNameSpaced.trim(); +console.log(driverNameSpaced); + +// Iteration 3.2 + +let chars = hacker2.split(""); +chars.reverse(); +let reversedName = chars.join(""); + +console.log(reversedName); + +// Iteration 3.3 + +if (hacker1 > hacker2) { + console.log("The driver's name goes first."); +} else if (hacker1 < hacker2) { + console.log("Yo, the navigator goes first, definitely."); +} else { + console.log("What?! You both have the same name? "); +}