Dressed to impress


#1

Hey gang.

I'm getting "SyntaxError: missing before statement" with the code below. I've looked through the other posts for this lesson, and as near as I can tell, my code should work. I've reloaded the browser two or three times. Any help would be appreciated. Thank you.
https://www.codecademy.com/courses/objects-ii/1/3?curriculum_id=506324b3a7dffd00020bf661#

var suitcase = {
    shirt: "Hawaiian"
};
if (suitcase.hasOwnProperty('shorts')) {
    console.log(suitcase.shorts);
}
else {
    suitcase.shorts = 'You didn't pack any shorts.';
    console.log suitcase.shorts;
};

#2

The syntax highlighting in your post does a pretty good job of answering your question.

As a suggestion, when you can't find errors, run it through some other interpreter with more verbose error messages. You can use your browser, nodejs, or some online one.


#3

with respect, as new coder, that's not terribly helpful. For instance, "hawaiian" in the first line is highlighted, but that's the default code.


#4

Then you'll want to keep looking, right. See any oddities in the coloring?
Being new doesn't excuse you from looking!


#5

try this one:

var suitcase = {
shirt: "Hawaiian"
};

if(suitcase.hasOwnProperty('shorts'))
{
console.log(suitcase.shorts);
}
else{
suitcase.shorts="red";
console.log(suitcase.shorts);
};


#6

Hey madwatch, its pretty simple. You have to put console.log(suitcase.shorts), as well as suitcase.shorts = "You didn't pack any shorts". The difference is there is the two quotations, ", instead of one, '. I hope this helped!


#7

Theres an even clever way to do this, kill two birds with one stone type of way. It's like a reverse else statement written as an if statement


#8

thanksss, cool answer


#9

The error is in the else statement. You opened your string with ' and closed it with ' after didn. Then t, pack, any, and shorts are undefined, and it expects a method after shorts because of the .. Then, after shorts, you open another string that contains ;, console.log suitcase.shorts;, and };. If you want to put ' inside a string as plain text, use \'. The \ will not appear. Also, you need to add () for console.log. And finally, you shouldn't put a ; after the }. This means that in the end, your code should look like:

var suitcase = {
    shirt: "Hawaiian"
};
if (suitcase.hasOwnProperty('shorts')) {
    console.log(suitcase.shorts);
}
else {
    suitcase.shorts = 'You didn\'t pack any shorts.';
    console.log(suitcase.shorts);
}

#10

Do not just do this, it expects a closing ' inside of ""

var suitcase = {
    shirt: "Hawaiian"
};
if (suitcase.hasOwnProperty('shorts')) {
    console.log(suitcase.shorts);
}
else {
    suitcase.shorts = "You didn't pack any shorts.";
    console.log(suitcase.shorts);
}