Skip to content
Closed
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
40 changes: 38 additions & 2 deletions starter-code/basic-algorithms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@
// Names and Input
const hacker1 = "Rakeem";
const hacker2 = prompt("What is your name?");
console.log(`The driver's name is ${hacker1}`);
console.log(`The navigator's name is ${hacker2}`);

// Conditionals
if (hacker1.length === hacker2.length) {
console.log(`Wow, you both got equally long names, ${hacker1.length} characters!!`);
} else {
hacker1.length > hacker2.length
? console.log(`The driver has the longest name, it is ${hacker1.length} characters.`)
: console.log(`Yo, navigator got the longest name, it has ${hacker2.length} characters`);
}

//Conditionals
// Loops
// Print driver name all caps on one line
function capitalizeDriver() {
let name = "";
for (let i = 0; i < hacker1.length; i++) {
name += `${hacker1[i].toUpperCase()} `;
}
console.log(name);
}
capitalizeDriver("Rakeem");

function reverseNavigator() {
return hacker2
.split("")
.reverse()
.join("");
}
reverseNavigator();

// Lorem ipsum generator
function alphaOrderStrings(navigator, driver) {
const nameArray = [navigator, driver];
nameArray.sort();
if (navigator === driver) {
return "What?! You both got the same name?";
}
return nameArray[0] === navigator ? "Yo, the navigator goes first definitely" : "The driver's name goes first";
}
alphaOrderStrings(hacker2, hacker1);