Skip to content
Open
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
49 changes: 49 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,56 @@
// Iteration 1: Names and Input
console.log("I`m ready");

let hacker1 = "The driver's name is Leal";

Choose a reason for hiding this comment

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

Here, instead of passing the variable as the whole string, you could've given just your name and console.log the string after, like:

const hacker1 = 'Leal';
 console.log(`The driver's name is ${hacker1}.`);
 const hacker2 = 'Duarte';
 console.log(`The navigator's name is ${hacker2}.`)

let hacker2 = "The navigator's name is Duarte";

// Iteration 2: Conditionals

let driverName = hacker1.slice(21);

Choose a reason for hiding this comment

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

So here you wouldn't need to use slice();

let navigatorName = hacker2.slice(24);



let numOfCharDriver = driverName.length;
let numOfCharNavigator = navigatorName.length;


if( driverName.length > navigatorName.length){

Choose a reason for hiding this comment

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

Great job on creating the variables numOfCharDriver and numOfCharNavigator . Here on the if statement, you could've used them like:

if( numOfCharDriver > numOfCharNavigator)

console.log("The driver has the longest name, it has " + numOfCharDriver + " characters");
}
if(driverName.length < navigatorName.length){
console.log("It seems that the navigator has the longest name, it has "+ numOfCharNavigator + " characters.");
}
else {
console.log("Wow, you both have equally long names, " + numOfCharDriver + " characters!");
}


// Iteration 3: Loops

//3.1
for (let i = 0; i < driverName.length; i++) {

Choose a reason for hiding this comment

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

Here, the idea was to print all the characters of the driver's name, separated by a space and in capitals i.e. "L E A L".

A good solution would be:

let withSpace = '';
for (let i = 0; i < hacker1.length; i++) {
     withSpace += hacker1.[i] + ' ';
 }
console.log(withSpace.toUpperCase());

console.log(driverName.toUpperCase()[i]);
console.log(driverName.toUpperCase()[0]+ " " + driverName.toUpperCase()[1] + " " + driverName.toUpperCase()[2] + " " + driverName.toUpperCase()[3]);
}

//3.2

for(let i = navigatorName.length -1 ; i >= 0; i--){

Choose a reason for hiding this comment

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

Here, the idea was to print all the characters of the navigator's name in reverse order. i.e. "etrauD"

One way of doing that:

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

console.log(navigatorName[i]);
}

//3.3

if (hacker1 > hacker2) {

console.log (`The driver's name goes first.`)

} else if (hacker1 < hacker2) {

console.log (`Yo, the navigator goes first definitely.`)

} else {

console.log (`What?! You both have the same name?`)
}