[solved] #8 Dress to impress

var suitcase = {
    shirt: "Hawaiian"

function test(input) {
        return suitcase.shorts = "red";    

Why does this work? Is it correct, or is it not correct?


Please format your post as I have done (select entire code block; press Ctrl+Shift+C) from next time. Thanks! :smile:

The code executes without error. But, I think that it has many logical errors. If this is a exercise related question, I would be able to help better if you give the exercise link.

I don't see a reason why it shouldn't work. Could you please state the statement which is difficult to comprehend for you so I can explain it?


Is the link, i've seen other people do it differently and i'm wondering if I've done it correctly.


Well it explains in the lesson that ".hasOwnProperty()" in an object means that the variable in an object already has a value:

var object = {
   variable: "value"

if (object.hasOwnProperty("variable")){

  //the variable has a value so it will run the code here!

I hope this explains your inquiry. If you need me to rephrase this just let me know and I'll see what I can do!


Thanks, but is my code correct for the lesson, it passes but is it correct?


Judging by the aim of the error, your code should not work because the exercise expects you to check if suitcase has the property shorts, not input. Compare:

function test(input) {
    if(suitcase.hasOwnProperty("input")){ // input string; your code


function test(input) {
    if(suitcase.hasOwnProperty(input)){ // input variable; expected code

and see where you gone wrong. Also, instead:

return suitcase.shorts = "red";

you should have:

console.log(suitcase.shorts = "red");

as the exercise expects you to set the shorts property to any value you wish using dot notation. Then print the value of the shorts property.

But the SCT is pretty lenient here so you passed nevertheless.


Thank you my friend.