Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Unsubscribed User
17,284 PointsJavascript Help
I need help getting this to pass...Thanks
/*
The goal is to replace all words in the below sentence with "chirp",
except replace food with "yum". The
assertions at the end of this section should pass when you're done.
*/
function assert(expression, failureMessage) {
if (!expression) {
console.warn("assertion failure: ", failureMessage);
}
}
var sentence = 'More food please.';
var words = sentence.split(' ');
var i= 0, length = words.length;
var replaceWith;
while( i < length ) {
if ( words[i] === ‘food’ ) {
replaceWith = ‘yum’;
}
else {
replaceWith = ‘chirp’;
}
sentence.replace( words[i], replaceWith );
i++;
}
console.log(sentence);
assert(sentence === "chirp yum chirp.", "sentence should have 2 chirps and a yum");
1 Answer
Unsubscribed User
17,284 PointsAnybody know why this is not working?