From 1fb4863a54312f1713089780586a4303cae765f5 Mon Sep 17 00:00:00 2001 From: MMARTID Date: Wed, 13 Nov 2024 18:53:24 +0100 Subject: [PATCH] Solved Lab --- .vscode/settings.json | 3 +++ index.js | 53 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..9607d34b3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "livePreview.defaultPreviewPath": "/index.html" +} \ No newline at end of file diff --git a/index.js b/index.js index 6b0fec3ad..d241965f0 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,58 @@ // Iteration 1: Names and Input +const hacker1 = "Maria" +const hacker2 = "Miguel" +console.log(`the navigator's name is ${hacker1}`) +console.log(`the driver's name is ${hacker2}`) // Iteration 2: Conditionals +let chars1 = hacker1.length +let chars2 = hacker2.length + + +if (chars1 > chars2) { + console.log(`The hacker1 has the longest name, it has ${chars1} characters`) +} else if (chars2 > chars1) { + console.log(`It seems that the hacker2 has the longest name, it has ${chars2} characters.`) +} + +// Iteration 3: Loops + + +let bySpaceBox = "" +for (let i = 0; i < hacker1.length ; i++){ + bySpaceBox += hacker1[i].toUpperCase() + " " + +} +console.log(bySpaceBox) + + +//Iteration 3.2 +let reversedBox = "" +for (let j = hacker2.length - 1 ; j>=0 ; j --){ + reversedBox += hacker2[j] + +} +console.log(reversedBox) + + + +//Iteration 3.3 +let ordenLexico1 = hacker2.localeCompare(hacker1) +let ordenLexico2 = hacker1.localeCompare(hacker2) + +if (ordenLexico1 > ordenLexico2){ + console.log("Yo, the navigator goes first, definitely") +} else if (ordenLexico2 > ordenLexico1){ + console.log("The driver's name goes first.") +}else if (!ordenLexico1 && !ordenLexico2){ + console.log("What?! You both have the same name?") +} + + + + + + -// Iteration 3: Loops