jrough
6/17/2016 8:32:00 PM
On Thursday, June 16, 2016 at 12:59:00 AM UTC-7, Jake Jarvis wrote:
> Am 16.06.2016 um 05:23 schrieb JRough:
> > I get the error : unexpected end of input, there is some logic error before it joins the words.
> >
> > 'use strict';
> > var sentences = [
> > "I now took the measure of the bench, and found that it was a foot too short; but that could be mended with a chair.",
> > "But it was a foot too narrow, and the other bench in the room was about four inches higher than the planed one--so there was no yoking them.",
> > "I then placed the first bench lengthwise along the only clear space against the wall, leaving a little interval between, for my back to settle down in.",
> > "But I soon found that there came such a draught of cold air over me from under the sill of the window, that this plan would never do at all, especially as another current from the rickety door met the one from the window, and both together formed a series of small whirlwinds in the immediate vicinity of the spot where I had thought to spend the night.",
> > "The devil fetch that harpooneer, thought I, but stop, couldn't I steal a march on him--bolt his door inside, and jump into his bed, not to be wakened by the most violent knockings? It seemed no bad idea; but upon second thoughts I dismissed it.",
> > "For who could tell but what the next draught, so soon as I popped out of the room, the harpooneer might be standing in the entry, all ready to knock me down!"
> > ];
> >
> > var badwords = ['window', 'chair', 'knockings'];
> >
> >
> > // Fill in function body here
> > var hasBadwords = function (message, index ) {
> > var words = message.split(" ");
> > words.map(function(word,index){
> > if (word == 'window' || word == 'chair' || word == 'knockings'){
> > return true;
> > } else {
> > return false;}
> > });
> >
> > // Tell us what the output is from running this code:
> > console.log(sentences.map(function (sentence, index) {
> > return hasBadwords(sentence) ? index : '';
> > }).join(''));
> >
>
> The error message apparently is "Uncaught SyntaxError: Unexpected end of
> input" and it is used by at least Chrome.
>
> In Firefox the message is different: "SyntaxError: missing } after
> function body".
>
> Do you use an editor with syntax highlighting?
I would still like this to work either way, Thomas' way or my way. It may be bogus but its an exercise of using the map function. I fixed the complaints and it still doesn't work.
var hasBadwords = function (message, index ) {
var bool;
var badwords = ['window', 'chair', 'knockings'];
var words = message.split(" ");
words.map(function (word, index) {
for (var i=0; i< badwords.length; i++){
if (word == badwords) {
bool = true;
}else {
bool = false;}
};
}
);
return bool;
};
// Tell us what the output is from running this code:
console.log(sentences.map(function (sentence, index) {
return hasBadwords(sentence) ? index : '';
}).join(''));</script>
</body></html>