Skip to content

[LIS-FT-012023] Alexandre Álvaro #2

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 7 commits into
base: main
Choose a base branch
from

Conversation

AleAlvo
Copy link

@AleAlvo AleAlvo commented Jan 16, 2023

  • Added all 3 Iterations for the day 1 lab.
  • Added the bonus exercises
  • Streamlined bonus 1
  • Corrected bonus 1 after TA's commentaries

@AleAlvo AleAlvo changed the title [LIS-FT-2023] Alexandre Álvaro [LIS-FT-012023] Alexandre Álvaro Jan 16, 2023
index.js Outdated
@@ -47,9 +47,15 @@ if (nameWithSpace.localeCompare(nameBackwards) < 0) {

let longText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque auctor id nisl eu imperdiet. Nullam pretium enim nec est sodales, et vestibulum odio varius. Morbi sit amet mauris nec ex luctus congue. Sed porttitor dui id velit mattis, quis pretium libero gravida. Suspendisse sagittis tellus vitae enim pulvinar tempus. Praesent vel est accumsan, laoreet dolor quis, dictum orci. Vestibulum id elit sollicitudin, luctus turpis eu, sagittis metus. Integer vitae dolor eget quam luctus gravida. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nunc eu nulla gravida, porttitor metus et, pellentesque ante. Integer rutrum posuere ipsum et tempus. Proin ac molestie enim. Nunc sit amet cursus tellus. Pellentesque ut pellentesque odio. Ut faucibus maximus lorem nec faucibus. Morbi sed tellus a massa varius pellentesque ut eget tortor. Nam ornare pharetra mauris, ut ornare justo. Proin ultricies dolor scelerisque massa eleifend pellentesque. Etiam venenatis metus sit amet leo dignissim, in ornare arcu euismod. Vivamus eget ex imperdiet dui semper fringilla quis tincidunt nibh. Duis vel ante at metus consequat porttitor ac nec nulla. Integer ac ante in orci feugiat pulvinar sed quis diam. Praesent fringilla enim sed nulla efficitur, eu pharetra est vestibulum. Suspendisse vestibulum sem eu lorem cursus, eget porttitor ligula sodales. Proin elementum urna vel massa gravida, sed commodo neque eleifend. Suspendisse gravida sapien dui, vitae sollicitudin urna ullamcorper quis. In mattis vehicula lacus nec cursus. Fusce sit amet eros condimentum, fringilla metus ac, semper orci. Etiam tristique pretium erat et interdum. Aliquam feugiat dictum odio sed tempor. In facilisis eu ligula sit amet viverra. Duis viverra nibh ut ex fringilla, ut scelerisque nisi auctor. Donec consequat sapien lectus, quis dapibus lectus varius nec. Ut in turpis vitae eros congue pulvinar in ac nibh. Integer laoreet dapibus purus vitae laoreet. Curabitur et tellus vel mi dignissim blandit."

console.log(longText.length);
Copy link

Choose a reason for hiding this comment

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

This way you're counting all the characters in the text. In the instructions they ask you to count just the words. One way of doing this is by counting the spaces in the text:

let wordCounter = 1;

for (let i = 0; i < longText.length; i++) {
  if (longText[i] === " ") {
    wordCounter += 1;
  }
}

console.log(wordCounter);

let etCount = longText.split("et");
console.log(etCount.length - 1);
let etCount = 0;
for(let i = 0; i < longText.length; i++) {
Copy link

Choose a reason for hiding this comment

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

The logic is pretty much what you've done here but you need to check for spaces as well, otherwise you will count every time et appears, even if it is in the middle of a word:

let etCounter = 0;

for (let i = 0; i < longText.length; i++) {
  if ( longText[i] === " " && longText[i + 1] === "e" && longText[i + 2] === "t" && longText[i + 3] === " ") {
    etCounter += 1;
  }
}

console.log(etCounter);

@joaopdg
Copy link

joaopdg commented Jan 17, 2023

Great job on the lab Alexandre, bonus done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants