Skip to content

LIS-WDFT-APR23-TOMÁS-ROSHAN #25

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
84 changes: 84 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,91 @@
// Iteration 1: Names and Input

let hacker1 = "Tomás";
console.log(`The driver's name is ${hacker1}`);
let hacker2 = "Roshan";
console.log(`The navigator's 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 (hacker1.length < hacker2.length) {
console.log(`It seems that the navigator has the longest name, it has ${hacker2.length} characters.`);
} else {
console.log(`Wow, you both have equally long names, ${hacker1.length} characters!`);
}


// Iteration 3: Loops
let driverName = "";
for (let i = 0; i < hacker1.length; i++) {
driverName += hacker1[i].toUpperCase() + " ";
}
console.log(driverName.trimEnd());

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

console.log(reverseNavName);


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


//BONUS 1


let longText = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam mattis sem quis massa varius, id volutpat orci sagittis. Nam porttitor sodales hendrerit. Nullam vel purus eget lacus fermentum aliquam. Proin dictum dui sit amet eros pretium, sed eleifend purus suscipit. Curabitur dignissim volutpat lobortis. Curabitur rhoncus at ligula et varius. Cras hendrerit metus a lorem bibendum varius. Morbi sit amet tellus vel massa scelerisque sagittis. Pellentesque eget malesuada est, a ultrices enim. Aliquam eu eleifend purus.
Nullam ante ante, vestibulum quis imperdiet sit amet, gravida id nisl. Curabitur vitae suscipit est. Phasellus dictum in velit vel scelerisque. Fusce tempus lobortis risus ac posuere. Praesent maximus enim sapien, semper mollis magna faucibus vitae. Pellentesque vel condimentum diam. Interdum et malesuada fames ac ante ipsum primis in faucibus. Etiam a ullamcorper quam. Donec vestibulum varius dolor, gravida commodo augue volutpat rhoncus.
Vestibulum dignissim dignissim ligula, auctor blandit nisl luctus scelerisque. Duis id enim congue, feugiat tortor a, elementum metus. Ut non erat at lectus eleifend tristique. Suspendisse sodales interdum arcu sed congue. Maecenas non consectetur sapien. Sed at imperdiet ex. Donec et auctor magna. Duis ultricies lectus odio, sed auctor sapien viverra in. Aenean viverra, velit ac euismod porta, metus lectus consequat mi, a placerat velit justo vel ligula. In pulvinar eros urna, in imperdiet sem dignissim sed. Phasellus vulputate tincidunt ante sed hendrerit. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.`;

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

if (longText[i] === " ") {
totalWords ++;
}
}
console.log(totalWords);

let count = 0;

for (let i = 0; i <longText.length; i++) {
let twoChars = longText[i] + longText[i + 1];

if (twoChars === "et") {
count++;
}
}

console.log(count);


// BONUS 2


let phraseToCheck = "Palindrome";
let firstHalf = phraseToCheck.slice(0,5);
let secondHalf = phraseToCheck.slice(5,10);
let reverseSecondHalf = "";

Choose a reason for hiding this comment

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

This is a cool way of logical thinking, however, it is not all correct. That just checks correctly words that are exactly 10 characters long.

A solution for that iteration is a bit more complex. I can leave you here one approach that you can use:

let stringToCheck = 'A man, a plan, a canal, Panama!';

stringToCheck = stringToCheck.replace(/[ ,!.]/g, '').toLowerCase();

let reversedString = stringToCheck.split('').reverse().join('');

if (stringToCheck === reversedString) {
  console.log('String is a palindrome');
} else {
  console.log('Not a palindrome');
}

for (let i = secondHalf.length -1; i>=0; i--) {
let charPhraseToCheck = secondHalf[i];
reverseSecondHalf += charPhraseToCheck;
}
if (reverseSecondHalf === firstHalf) {
console.log("It's a Palindrome!");
} else {
console.log("It's not a Palindrome!");
}
Empty file added test.js
Empty file.