forked from ironhackbcn/lab-javascript-basic-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-algorithms.js
More file actions
41 lines (32 loc) · 1.17 KB
/
basic-algorithms.js
File metadata and controls
41 lines (32 loc) · 1.17 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
32
33
34
35
36
37
38
39
40
41
//variables
var hacker1 = "Samuel"
var hacker2 = window.prompt("what is the navigators name?")
//console logs
console.log(`The drivers name is ${hacker1}`);
console.log(`The navigators name is ${hacker2)}`)
//Let's get looping
for (var i = 0; i < hacker1.length || hacker2.length; i++){
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(`Yo, navigator got the longest name, it has ${hacker2.length} characters`)
} else {}
console.log(`wow, you both got equally long names, ${hacker2.length} characters!!`)
}
//loop drivers name
for(let i = 0; i < hacker1.length; i++){
console.log(`${hacker1[i]}`)
}
//loops driver name backwards
for(let i = hacker.length; i > 0; i--){
console.log(`${hacker1[i]}`)
}
//loop on first letter..
for(let i = 0; i < 1; i++){
if (hacker1[0] === "a"){
console.log(`The driver's name goes first`)
} else if (hacker2[0] === "a"){
console.log(`Yo, the navigator goes first definitely`)
} else {}
console.log(`What?! You both got the same name?`)
}