Codecademy - Mini Linter completion

Hello, here is my code for the mini Linter project. This one cause frustration all because of syntax errors, please go through my code and let me know what i can improve to make this work smoothly and better to read and understand. Thank you.

let story = 'Last weekend, I took literally the most beautiful bike ride of my life. The route is called "The 9W to Nyack" and it actually stretches all the way from Riverside Park in Manhattan to South Nyack, New Jersey. It\'s really an adventure from beginning to end! It is a 48 mile loop and it basically took me an entire day. I stopped at Riverbank State Park to take some extremely artsy photos. It was a short stop, though, because I had a really long way left to go. After a quick photo op at the very popular Little Red Lighthouse, I began my trek across the George Washington Bridge into New Jersey.  The GW is actually very long - 4,760 feet! I was already very tired by the time I got to the other side.  An hour later, I reached Greenbrook Nature Sanctuary, an extremely beautiful park along the coast of the Hudson.  Something that was very surprising to me was that near the end of the route you actually cross back into New York! At this point, you are very close to the end.';

let overusedWords = ['really', 'very', 'basically'];

let unnecessaryWords = ['extremely', 'literally', 'actually' ];
// Step 3
let storyWords = story.split(' ');
// console.log(storyWords.length);
//console.log(storyWords)
let betterWords = storyWords.filter(word => {
  return !unnecessaryWords.includes(word)
}
)
// console.log(betterWords)
// Step 4
let reallyCount = 0;
let veryCount = 0;
let basicallyCount = 0;

for (word of storyWords) {
  if (word === "really"){
    reallyCount++
  } else if(word === "very") {
    veryCount++
  } else if(word === "basically") {
    basicallyCount++
  }
}
/*
console.log('really count', reallyCount)
console.log('very count', veryCount)
console.log('basically count', basicallyCount)
*/
// Step 5
 let sentenceCount = 0;

for (sentence of storyWords) {
   if (sentence[sentence.length-1] === '.') {
     sentenceCount++
   } else if (sentence[sentence.length-1] === '!') {
     sentenceCount++
   }
 }
console.log('Word count: ', storyWords.length )
console.log('Sentence count: ', sentenceCount)
console.log('Really count: ', reallyCount)
console.log('Very count: ', veryCount)
console.log('Basically count: ', basicallyCount)

console.log(betterWords.join(' '));

Giving feedback for the first time? AWESOME! Check out this video for a boost of confidence: How to Review Someone Else’s Code
Feel free to remove this message before posting.

Cheers!
—Codecademy Community Managers

Hello! I also did this task (it’s Iterators chapter - Project Mini Linter) and have some questions.

paulieb99, I want to share my thoughts answering your question.

  1. Step 4. I think the variant with if/else not correct. If we change our array overusedWords code won’t work. I think programming should be universal, so I used 1st variant with nested loop:
let overusedWordCount = [];
overusedWords.forEach(word => {
  overusedWordCount[word] = 0;
})

overusedWords.forEach(overusedWord => {
  betterWords.forEach(word => {
    if (word === overusedWord) {
      overusedWordCount[overusedWord]++;
    }
  });
});

here we get an array with all overused word of given array and values for it. But also I confused that the array iterates twice. Maybe there is another way to determine are numbers without repeat loop?

  1. Step 5. No reason to use if/else if. You can check it with one condition like that:
if (word.slice(-1) === '.' || word.slice(-1) === '!') {
  sentenceCount++;
}

also here I use method .slice() to determine last symbol of element.

  1. Step 6. Here I created a function to log out:
const logNumbers = (word, sentence, overused) => {
  console.log(`Count of words: ${word}`);
  console.log(`Count of sentences: ${sentence}`);
  console.log(`Count of overused: ${overused}`);
}
logNumbers(storyWordsCount, sentenceCount, overusedWordCount);

but string with ${overused} don’t work. I understand that this is an array. I tried to use iterators and overused[0] but it doesn’t work. Maybe someone can help me.

4 Likes

Here’s my solution for the Mini Linter project.

Not sure if it’s similar to other people’s or the official solution (I only watched one part of it)

let overusedWords = [‘really’, ‘very’, ‘basically’];

let unnecessaryWords = [‘extremely’, ‘literally’, ‘actually’ ];

const storyWords = story.split(’ ');
console.log(storyWords);
console.log(storyWords.length);

const betterWords = storyWords.filter((storyWords) => {
return storyWords !== unnecessaryWords;
});

console.log(betterWords);
console.log(betterWords.includes(unnecessaryWords));

let reallyNum = 0;
let veryNum = 0;
let basicallyNum = 0;

for (word of betterWords) {
if (word === ‘really’)
reallyNum ++
if (word === ‘very’)
veryNum ++
if (word === ‘basically’)
basicallyNum ++
}

// console.log(‘really: ’ + reallyNum + ’ times’);
// console.log(‘very: ’ + veryNum + ’ times’);
// console.log(‘basically: ’ + basicallyNum + ’ times’);

function countSentences(storyWords) {
let count = 0;
const marks = [“.”, “!”];

for (let mark of story) {
if (marks.includes(mark)) {
count++;
}
}
return count;
}

console.log(storyWords.length);
console.log(countSentences(storyWords));
console.log(‘really: ’ + reallyNum + ’ times’);
console.log(‘very: ’ + veryNum + ’ times’);
console.log(‘basically: ’ + basicallyNum + ’ times’);

console.log(betterWords.join(’ '));