Skip to content

Commit b49edcd

Browse files
committed
iterations 1,2,3: Done
1 parent f3a2616 commit b49edcd

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

index.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,59 @@
1+
/** @format */
2+
13
// Iteration 1: Names and Input
4+
const hacker1 = "Greg"; // 1.1
5+
const hacker2 = "Viktor"; // 1.2
26

7+
console.log(`The driver's name is ${hacker1}`); // 1.3
8+
console.log(`The navigator's name is ${hacker2}`); // 1.4
39

410
// Iteration 2: Conditionals
511

12+
//2.1
13+
14+
const hacker1Length = hacker1.length;
15+
const hacker2Length = hacker2.length;
16+
17+
if (hacker1Length > hacker2Length) {
18+
console.log(
19+
`The driver has the longest name, it has ${hacker1Length} characters.`
20+
);
21+
} else if (hacker2Length > hacker1Length) {
22+
console.log(
23+
`It seems that the navigator has the longest name, it has ${hacker2Length} characters.`
24+
);
25+
} else {
26+
console.log(
27+
`Wow, you both have equally long names, ${hacker2Length} characters.`
28+
);
29+
}
630

731
// Iteration 3: Loops
32+
33+
// 3.1
34+
35+
let hacker1Name = "";
36+
for (let i = 0; i < hacker1Length; i++) {
37+
hacker1Name += hacker1[i].toUpperCase() + " ";
38+
}
39+
console.log(hacker1Name);
40+
41+
// 3.2
42+
43+
let hacker2Name = "";
44+
45+
for (let i = hacker2Length - 1; i >= 0; i--) {
46+
hacker2Name += hacker2[i];
47+
}
48+
console.log(hacker2Name);
49+
50+
// 3.3 locale.compare
51+
52+
const comparison = hacker1.localeCompare(`${hacker2}`);
53+
if (comparison < 0) {
54+
console.log("The driver's name goes first.");
55+
} else if (comparison > 0) {
56+
console.log("Yo, the navigator goes first, definitely.");
57+
} else {
58+
console.log("What?! You both have the same name?");
59+
}

0 commit comments

Comments
 (0)