For...in over an object?

This is all it gives me…

javascript_evaluator@0.0.0 test /usr/src/app
mocha --require babel-polyfill --compilers js:babel-core/register “/usr/src/app/test/unit_tests_spec.js”

studentCode
1) logs the values of the object

0 passing (23ms)
1 failing

  1. studentCode logs the values of the object:

    AssertionError: expected to deeply equal [ ‘name’, ‘matt’, ‘age’, 58 ]

    • expected - actual

    -
    +[

    • “name”
    • “matt”
    • “age”
    • 58
      +]

    at Context. (test/unit_tests_spec.js:31:25)

npm ERR! Test failed. See above for more details.

I’m ready to throw my computer out the window.

I posted everything that is said on the page…

“Use a for…in loop to log each property and value in the object”

I did, and it didn’t work. I have to go for now for a few hours. I thank you again for being such a hero. Sorry I’m a moron.

function studentCode(console) {
    var arr = [];
    var obj = {
    name: 'matt',
    age: 58
    
    }
    for (var i in obj){
    arr.push(i, obj[i]);
  }
return arr;
}
studentCode(console)
function studentCode(console) {
  var obj = {
    name: 'matt',
    age: 58
  }

  // log the key
  // then log the value
}

For the love of science…can someone please tell me what is wrong here? My head wants to explode.

I don’t believe I need a return statement. It is just going to the console.

This is what I have currently. Not even sure if I create a new array because it didn’t like two sets of brackets?

function studentCode(console) {
  var obj = {
    name: 'matt',
    age: 58
  }
  for (var i in obj){
     console.log(obj[i]);
  }
}
studentCode(console)

No, I did listen to you and it didn’t work…

function studentCode(console) {
    var arr = [];
    var obj = {
    name: 'matt',
    age: 58
    
    }
    for (var i in console){
    arr.push(i, console[i]);
  }
return arr;
}
studentCode(console)

Just noticed Randell started replying just as I did so I’ll change what I’m saying

I think you need to find the instructions again and let us know exactly what it says

It seems weird to me that the argument to the function is called console, it seems weird that there’s a hardcoded obj inside the function, however…

@camperextraordinaire I think the question really is as weird and wrong as it sounds, I think the function signature might be off, but from a teensy bit of google-fu there’s a paid-for set of challenges that’s suspiciously similar to the question here, where all you have to do is console log the key then the value of the hard-coded obj

@rstorms when you posted that screenshot above, was it with the code reset to exactly how it was at the start?

I believe I am making it way too difficult for myself and overthinking it. I solved all the other challenges after it and this one has me stumbling ALL day.

I changed the name and age to protect myself…didn’t know if I can share these challenges, but this is what I get when I press reset…

function studentCode(console) {
  var obj = {
    name: 'zoe',
    age: 40
  }

  // log the key
  // then log the value
}

I think the console is a fake one for the test which puts elements into an array or something - could be wrong here though!

So they might just want:

console.log(key);
console.log(value);

inside the for loop

1 Like

What information???

I’ll just jump out this window then.

I really think I might fail this bootcamp.

if you have time, consider trying FCC’s javascript section, it’s pretty good and would help a lot with the bootcamp, if you have time to do both

(and imo makes a lot more sense than the other questions I’ve seen from there…)

it’s hard to say we can help with the other questions really, we don’t know how they test things, what the questions ask, etc, but if you come across something you’re stuck with perhaps try the FCC question on a similar topic

should be e z p z :ok_hand:

EXACTLY! Why in the hell is an argument being passed? It only makes it more confusing! Do I actually write (var key in obj)? KEY??

Man I finished way past FCC javascript and feel like it only rooted somethings.

Also why don’t you go on over to w3schools? They have great references. Might not explain your question, but you’ll know what you’re dealing with just a little bit better.