From 66c15ab757e4654a50f4891aebfba3993dec2180 Mon Sep 17 00:00:00 2001 From: adrien-duchossoy Date: Wed, 6 May 2026 17:48:52 +0200 Subject: [PATCH] Exercise on javascript loops and conditionals --- index.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/index.js b/index.js index 6b0fec3ad..4ee93d30f 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,47 @@ // Iteration 1: Names and Input +const hacker1 = 'adrien' +console.log(hacker1) +const hacker2 = 'faith' +console.log(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(`The navigator has the longest name, it has ${hacker2.length} characters.`) +} else { + console.log(`Wow you both have equally long names, it has ${hacker1.length} characters.`) +} + // Iteration 3: Loops + +let driverNameSpaced = '' +for (let i=0; i=0; i--){ + navigatorNameReversed += hacker2[i] +} +console.log(navigatorNameReversed) + +const order = hacker1.localeCompare(hacker2) + +if (order<0) { + console.log("The driver's name goes first.") +} else if (order>0) { + console.log("Yo, the navigator goes first, definitely.") +} else { + console.log('What?! You both have the same name?') +} + + +//Bonus \ No newline at end of file