forked from ironhack-labs/lab-javascript-basic-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem1
More file actions
31 lines (31 loc) · 1.06 KB
/
Problem1
File metadata and controls
31 lines (31 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
console.log("I'm Ready!");
var hacker1 = "Claudia"
console.log ("The drivers name is " + hacker1);
var hacker2 = "Eleyni"
console.log ("The navigators name is " + hacker2);
if (hacker1.length > hacker2.length) {
console.log ("The driver has the longest name, it has " + hacker1.length + " characters")
} else if (hacker2.length > hacker1.length) {
console.log ("Yo, navigator got the longest name, it has " + hacker2.length + " characters")
} else if (hacker1.length = hacker2.length) {
console.log ("wow, you both got equally long names " + hacker2.length + " characters!")
}
var driver = " "
for (var i = 0; i < hacker1.length; i++) {
driver += hacker1.toUpperCase()[i] + " ";
}
console.log(driver)
function reverse(str) {
return str.split('').reverse().join('');
}
reverse(hacker2);
var names = [hacker1, hacker2];
names.sort();
console.log(names);
if (names.indexOf(hacker1)===0){
console.log("The drivers name goes first")
} else if (names.indexOf(hacker2)===0){
console.log("Yo, tha navigator goes first definitely");
} else {
console.log("what?! you both got the same name?");
}