Skip to content
Closed

Done #654

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
105 changes: 103 additions & 2 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,108 @@
// Iteration 1: Names and Input

console.log("I'm ready!");
const hacker1 = 'Friso';
console.log('The driver name is '+hacker1)
const hacker2 = 'Boris';
console.log('The navigator name is '+hacker2);

// Iteration 2: 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(`It seems that the navigator has the longest name, it has ${hacker2.length} characters.`)

}
else if (hacker1.length === hacker2.length) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can also just use an "else" statement here

console.log(`Wow, you both have equally long names, ${hacker1.length} characters!.`)

}

// Iteration 3: Loops

hacker1Uppercase = hacker1.toUpperCase()
nameWithSpaces = '';
for (let i = 0; i < hacker1Uppercase.length; i++) {
console.log(hacker1Uppercase[i] );
nameWithSpaces += `${hacker1Uppercase[i]} `;
nameReverseOrder = '';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If you're not using it inside the loop, It's better to define nameReverseOrder in the global scope.

}
console.log(nameWithSpaces);
for (let j = hacker2.length -1; j > 0; j-- ) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

in the for loop, you should use "j>=0" otherwise the first letter won't print.


nameReverseOrder += `${hacker2[j]}`;

}

console.log(nameReverseOrder);

// Lexical order


if (hacker1 === hacker2) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think you meant to use "hacker1.length === hacker2.length"


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

}

else if (hacker1.localeCompare(hacker2) === -1) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again you can use the ".length" property here


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

else if (hacker1.localeCompare(hacker2) === 1) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again you can use the ".length" property here

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

}


// Bonus Time! Bonus 1:

const loremIpsumString = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam suscipit vitae dui in sodales. Aenean nec sem tincidunt, accumsan ipsum elementum, tincidunt urna. Phasellus dui augue, ultricies id neque id, tincidunt sagittis ante. Vivamus suscipit tempus ex eget dignissim. Praesent sed pellentesque neque. Aliquam at consequat arcu. Vivamus convallis scelerisque accumsan. Nunc mattis id sem in bibendum. Proin nec viverra urna. Donec facilisis nisl eu sodales semper. Donec odio quam, aliquam a sapien vel, porta malesuada enim. Phasellus pellentesque, magna venenatis venenatis faucibus, neque turpis pulvinar leo, finibus consectetur risus nisl a elit. Pellentesque ac risus vitae dui blandit pellentesque ac et tellus. Vestibulum eget elit finibus, blandit orci volutpat, sodales quam. Curabitur condimentum purus eget ligula rhoncus faucibus. Sed lectus sem, mollis vitae eleifend ut, elementum nec turpis. Vestibulum mattis magna ac lacus blandit, nec feugiat nibh ultricies. Donec nec libero augue. Aliquam ac turpis a ante rhoncus sodales. Mauris auctor dolor mauris, bibendum aliquam libero tristique vitae. Donec eget consequat ipsum. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed velit velit, pulvinar at iaculis ac, maximus ut risus. Proin ultrices nibh eu vulputate efficitur. Praesent libero mauris, hendrerit congue interdum id, feugiat non erat. Quisque mattis semper diam ut congue. Mauris elit mi, aliquet et volutpat at, placerat eget tortor. Nulla ut elementum ligula, sed commodo diam. Aliquam maximus, purus eu dignissim interdum, ante erat lobortis odio, nec gravida odio metus nec erat. Fusce sodales erat eros, nec aliquam lectus pellentesque elementum. Suspendisse et vestibulum leo, tempus finibus mauris. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Quisque et dignissim enim, fermentum pharetra orci. Curabitur fermentum non tortor vitae semper. In dignissim auctor mollis. Donec commodo ultricies dignissim. Fusce non nisl aliquam, lacinia turpis quis, vestibulum velit. Aenean arcu urna, pharetra eu felis sit amet, ultrices vulputate nibh.`

console.log(loremIpsumString);
console.log(loremIpsumString.length);

let counter = 0;

for (let i = 0; i < loremIpsumString.length; i++) {

if (loremIpsumString[i] === 'e' && loremIpsumString[i+1] === 't') {

counter++

}
}
console.log(`The text has ${counter} times 'et'`);

// Bonus 2:

let phraseToCheck = 'race car';
let phraseUpperCase = phraseToCheck.toUpperCase();
let phraseWithoutSpaces = '';
let phraseReverseOrder = '';

// delete spaces from the phrase
for (let i = 0; i < phraseUpperCase.length; i++) {
if (phraseUpperCase[i] === ' ') {
}
else {
phraseWithoutSpaces += `${phraseUpperCase[i]}`;
}
}

// Reverse the phrase
for (let j = phraseWithoutSpaces.length -1; j > -1; j-- ) {
phraseReverseOrder += `${phraseWithoutSpaces[j]}`;
}

// Check if it is a palindrome or not

// Iteration 3: Loops
if (phraseWithoutSpaces === phraseReverseOrder) {
console.log('This is a palindrome')
}
else {
console.log('This is not a palindrome');
}