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
42 changes: 41 additions & 1 deletion starter-code/basic-algorithms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,47 @@
// Names and Input

var hacker1 = “Kevin”;
var hacker2 = prompt(“Name the navigator”);
console.log(“The hacker is ” + hacker1);
console.log(“The navigator is ” + hacker2);

// the following command is upper casing, split and rejoining the string at once
console.log(hacker1.toUpperCase().split(‘’).reverse().join(' ’));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! 🙌


// Another way to do the command .split
var split = “”;
for(var i=0; i < hacker1.length;i++){
split += hacker1[i] + ” “;
}
console.log(“Manual method ” + split);

// Another way to do the command .reverse()
// We iterate over the index and not the number of characters,
// that’s why we remove 1 to the length, because the index start at 0
var reverse = [];
for (var i=hacker1.length-1; i>=0 ;i--){
reverse += hacker1[i];
}
console.log(reverse);

//Conditionals
var hacker1L = hacker1.length;
var hacker2L = hacker2.length;

// Name length check
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 ” + hacker2L + ” characters”);
} else if (hacker1.length == hacker2.length){
console.log(“wow, you both got equally long names, “+ hacker1L +” characters!!“);
}

// Lorem ipsum generator
// Name place in the alphabet
if (hacker2.localeCompare(hacker1) === 1){
console.log(“The driver’s name goes first”);
} else if (hacker2.localeCompare(hacker1) === -1){
console.log(“Yo, the navigator goes first definitely”);
} else {
console.log(“What?! You both got the same name?“);
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy