Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BCN-PT-1219-AlejandroJimenez#599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Changes fromall 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
75 changes: 73 additions & 2 deletionsjs/index.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,78 @@
// Iteration 1: Names and Input
// ------------------------------------------------------------------------------------

// 1.1 Create a variable `hacker1` with the driver's name.
const hacker1 = "Alejandro";

// Iteration 2: Conditionals
// 1.2 Print `"The driver's name is XXXX"`.
console.log("The driver's name is " + hacker1);

// 1.3 Create a variable `hacker2` with the navigator's name.
const hacker2 = "zAlberto";

// Iteration 3: Loops
// 1.4 Print `"The navigator's name is YYYY"`.
console.log("The navigator's name is " + hacker2);


// Iteration 2: NConditionals
// ------------------------------------------------------------------------------------

// 2.1. Depending on which name is longer, print:
const longHacker1 = hacker1.length;
const longHacker2 = hacker2.length;

if(longHacker1 > longHacker2){
console.log("The driver has the longest name, it has " + longHacker1 + " characters.");
}
else if (longHacker1 < longHacker2){
console.log("It seems that the navigator has the longest name, it has " + longHacker2 + " characters.");
}
else {
console.log("Wow, you both have equally long names, XX characters!.");
}



// Iteration 3: Loops
// --------------------------------------------------------------------------------------------------------------------

// 3.1 Print all the characters of the driver's name, separated by a space and in capitals i.e. "J O H N"
const name = "JOHN";
let splitname = name.split("");
let final = "";
let length = name.length;

for (let i = 0; i < length; i++){
final += splitname[i];
if(i < name.length -1){
final += " ";
}
}
console.log(final);



// 3.2 Print all the characters of the navigator's name, in reverse order. i.e. "nhoJ"
final = "";

while (length>=0) {
final = final + name.charAt(length);
length--;
}
console.log(final)



// 3.3 Depending on the lexicographic order of the strings, print:

console.log(hacker1.localeCompare(hacker2));

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

[8]ページ先頭

©2009-2025 Movatter.jp