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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5502
}
51 changes: 49 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,54 @@
// Iteration 1: Names and Input

var hacker1 = "Jackie";
console.log(` The driver's name is ${hacker1}`);
var hacker2 = "James";
console.log( ` The navigator's name is ${hacker2}`);

// Iteration 2: Conditionals
if (hacker1.length > hacker2.length) {
console.log( `The driver has the longest name ${hacker1.length} characters`);
}
else if (hacker1.length < hacker2.length) {
console.log(` It seems that the navigator has the longest name ${hacker1.length} characters`);


}
else {
console.log(`Wow, you both have equally long names`)
}
// Iteration 3: Loops

//---capital & Space---//
var updatedName = "";
for(let i = 0; i < hacker1.length; i++) {
updatedName += hacker1[i].toUpperCase() + " ";
}
console.log(updatedName);

// const lastIndex = hacker1.length - 1;
// for ( let i = 0; i <= lastIndex; i++) {
// const char = hacker1[i];
// console.log(char);
// }


// ---reverse---//
let newName = "";
var lastChar = hacker1.length - 1;
for (let i = lastChar; i >= 0; i--) {
newName += hacker1[i];
}
console.log(newName);
//---//

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare

const result = hacker1.localeCompare(hacker2);

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