Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LAB | JS Basic Algorithms</title>
<script src="index.js"></script>
</head>
<body>
<h1>LAB | JS Basic Algorithms</h1>
Expand Down
43 changes: 43 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,50 @@
// Iteration 1: Names and Input

const hacker1 = "bru";
const nameUpper = hacker1.toUpperCase();
console.log(`The drivers name is ${nameUpper}`);

const hacker2 = "bru";
console.log(`The navigators name is ${hacker2}`);

// Iteration 2: Conditionals

if (hacker1.length > hacker2.length) {
console.log(`the driver has the longest name, it has ${hacker1.length} characters!`)

} if (hacker1.length < hacker2.length) {
console.log(`the navigator has the longest name, it has ${hacker2.length} characters!`)

} else if (hacker1.length === hacker2.length) {
console.log(`Wow, you both have equally long names, ${hacker1.length} ${hacker2.length} characters!`)
}

// Iteration 3: Loops

/*const nameArray = nameUpper.split('');
console.log(nameArray)

const spacedName = nameArray.join(' ');

const reversedNameArray = nameUpper.split('');
reversedNameArray.reverse();
const reversedName = reversedNameArray.join('');

console.log(`The reverted name is ${reversedName}`);*/

let firstNameReversed = "";

for (let i = hacker2.length - 1; i >= 0; i--) {
firstNameReversed = firstNameReversed + hacker2[i];
}

console.log(`The reversed name is: ${firstNameReversed}`);

let resultComparation = hacker1.localeCompare(hacker2);
if (resultComparation < 0) {
console.log("The driver's name goes first.");
} else if (resultComparation > 0) {
console.log("Yo, the navigator goes first, definitely.");
} else {
console.log("What?! You both have the same name?");
}