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
32 changes: 30 additions & 2 deletions starter-code/basic-algorithms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
// Names and Input

let hacker1 = "Jesús";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Si son variables que no cambiarán es mejor utilizar const en vez de let.
Como regla general: Siempre utilizar const hasta que el código de error.

let hacker2 = "Miguel";
console.log("the driver's name is " + hacker1);
console.log("the navigator's name is " + hacker2);

//Conditionals

if(hacker1.length > hacker2.length){
console.log("The driver has the longest name, it has " + hacker1.length + " characters");
}else if (hacker1.length < hacker2.length){
console.log("Yo, navigator got the longest name, it has " + hacker2.length + " characters");
}else {
console.log("Wow, you both got equally long names," + hacker1.length + " characters!!");
}

// Lorem ipsum generator
let string1 = "";
for(let i = 0; i<=hacker1.length-1;i++){
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Si utilizáis espacios entre los operadores (let i = 0) utilizarlo para todos (i<=hacker1.length-1)

string1 = string1 +" "+ hacker1[i].toUpperCase();
}
console.log(string1);


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

if(hacker1.localeCompare(hacker2)===-1){
console.log("The driver's name goes first");
}else if(hacker1.localeCompare(hacker2)===1){
console.log("Yo, the navigator goes first definitely");
} else {
console.log("What?! You both got the same name?")
}