Now that we’ve removed the unnecessary words, let’s take care of any misspelled words in the story. We can reassign storyWords
to a new array of spell-checked words using the .map()
method!
Reassign storyWords
to equal the invocation of the .map()
method on the storyWords
array.
Setword
as a parameter of .map()
‘s callback function.
In the callback’s body, define a conditional statement to check if the word
argument is equal to the misspelledWord
variable. If it is, return the correct spelling of the string, “beautiful”. If not, return word
.
Take a look at the story
string in the console to see the correct spellings! You can see one instance of the spellchecked word in the first sentence of the story.
Links will be at : https://www.codecademy.com/courses/introduction-to-javascript/projects/mini-linter
Why can’t we use the return in a way like this:
var ten = 10;
var five = 5;
var returnLargerNumber = five < ten ? function() {
return ten;
} : function() {
return five;
};
console.log(returnLargerNumber()); // logs 10