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
34 changes: 31 additions & 3 deletions starter-code/basic-algorithms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
// Names and Input
var hacker1 = "Alma";
console.log(hacker1);

var hacker2 = prompt('How is the navigato\'s name?');
console.log(hacker2);


//Conditionals
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 ' + hacker2.length + ' characters'); }

/*Print all the characters of the driver's name, separated by a space and in capitals ie. "J O H N"*/
var upperCaseName = "";
for (i = 0; i < hacker1.length; i++) {
upperCaseName += hacker1[i].toUpperCase() + " ";
}
console.log(upperCaseName);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Muy bien!, como lo sabes hacer manualmente, échale un ojo a split( ) y join( ), seguro que te van a gustar


// Lorem ipsum generator
/*Print all the characters of the navigator's name, in reverse order. ie. "nhoJ"*/

var reversedName = "";
for (i = hacker2.length; i > 0; i--){
reversedName += hacker2[i-1];
}
console.log(reversedName);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Genial, como te comenté antes échales un ojo a los métodos de antes y también a reverse( )

/*lexicographic order of the strings*/
if (hacker1 < hacker2){
console.log("The driver's name goes first")
} else if (hacker2 < hacker1) {
console.log("Yo, the navigator goes first definitely")
} else {
console.log("What?! You both got the same name?");
}