For...in over an object?

I need to also print “name” and “age”, I just can’t figure out how?

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

Yes, I get this…

AssertionError: expected [ ‘matt58’ ] to deeply equal [ ‘name’, ‘matt’, ‘age’, 58 ]
+ expected - actual

EDIT: Essentially I need both name and age in there, too.

I’m not. This is a challenge from a website that needs an invitation. The instructions are “Use a for…in loop to log each property and value in the object”

Yes…i need name : Matt age : 58

You can’t. I need to console.log an array that shows the property and values.

I have this currently…

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

Still VERY confused why they have “console” as an argument for this function. Worst word to use.

Yeah, sorry. I never worked with for…in loops and somehow never went over these.

Yeah, this is what I looked at for reference and why I started with a string originally, just trying to work off of that. It’s obvious to me I need an array, but still not understanding how to use .push to add it to the array or console it? Ugh, these moments make my head explode.

Quite honestly, I’m not so sure. Either I’m tired or stupid. I have this, but maybe now I’m considering that I need an object instead?

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

EDIT: I would assume arr.push("Goodbye")

Sorry, I don’t understand what you mean when you say “your for loop represents the property name of the object.” Do you mean the property value? I tried arr.push(i) but only got the words name and age.

They want this…

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

How do I add both?

Definitely understand it’s the best way to learn, I’m just so frustrated. obj[i] is referencing to the object’s value, and i is referencing the object’s keys? I just don’t understand entirely so I can’t possibly figure out a solution.

Okay, so I did this then…

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

Closer, as I get ["namematt", "age58"], but not it…

BAH…

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

Can I not push both on the same line to make cleaner code?

EDIT: And this isn’t entirely the solution yet. It still shows me this…
AssertionError: expected [ [ ‘name’, ‘matt’, ‘age’, 58 ] ] to deeply equal [ ‘name’, ‘matt’, ‘age’, 58 ]
+ expected - actual

I have an extra set of brackets…

Return arr wrapped with []?

I’m sorry I’m the worst student to have ever walk the earth :frowning:

I just feel embarrassed I’m not good at this stuff at all. I don’t fully understand what they want me to do at this point.

When I do that it gives me…
AssertionError: expected [] to deeply equal [ ‘name’, ‘matt’, ‘age’, 58 ]
+ expected - actual

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)

Still gets the same error.