Day 2: Objects
-
dherran 9 years ago If the point was to learn objects why are we only being asked to console.log() something that is already set? You first say you are giving a single line that had to be put in an object. I though I had to split the string and save each column into the object. Instructions are not clear at all.
-
PRASHANTB1984 9 years ago See this isn't a usual challenge - it is also a tutorial. So, we handled the part where the string is split. Reading code is also a part of the learning. For someone completely new to programming this is quite essential.
-
jeancochrane 9 years ago You're definitely right that learning to read through code is essential, Prashant. At the same time, a hint telling us to read the code would have helped keep the focus on the lesson, rather than on aimless debugging – I agree with Paul's comment below, in that the previous challenges had trained us to ignore the code beneath our active functions. It was a little bit confusing, although not the end of the world. Anyway, thanks for helping me solve this one!
-
ibsavage 9 years ago IMHO, it would have been a better introduction of objects if the instructions were to print out myObject's properties individually.
-
-
Neurovibes 9 years ago Nowhere in the tutorial does it indicate the idea of creating a function that has no name... so in the part where it says "process.std.in(end'', function() {.. etc" ------------------------------------------------------------------------You create a variable called var myObject = new Object
So this "new Object" is it the default referral to the no-named function listed at the first line, i.e. "..., function () {" ? does that mean "Object" is a reserved keyword? -
Jancl0 9 years ago reading and understanding someone elses code is important, but the task suggests that we had to create the object ourselves
-
-
-
cristianlatapiat 8 years ago This is the solution!! :)
function printObjectProperty(myObject) { //Write your code here console.log(myObject); }
// The below code is to show how to create an Object. process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; });
process.stdin.on("end", function () { var obj = _input.split(' '); var myObject = new Object;
// Fill up the question marks myObject.type = obj[0] myObject.model = obj[1] myObject.color = obj[2] printObjectProperty(myObject);
});
-
vinayprajapati31 3 years ago Thank you so much
-
-
_mohitgarg 9 years ago Instructions are not clear what do i need to log car or myObject. if i need to log myObject what do i do with varaible car then. I m really confused. This simple challange is sucking up all my time!!
-
betkom Asked to answer 9 years ago Endorsed by _mohitgargYou are not supposed to create any variable. An object called myObject has been created and has been given it's fields and their respective values. The only thing you need to do is print out the object in the function 'printObjectProperty', the object is the argument passed into the 'printObjectProperty' function. Let me know if this helps.
-
kropen 5 years ago This is not correct, because mere printing of the object passes as correct answer but fails two test cases, which is never clarified.
-
-
sarbazx Asked to answer 9 years ago just myObject
-
shalinisinghsss4 9 years ago Exactly
-
-
shtolcers 9 years ago Agreed, instructions are not clear enough for task with so much additional code.
btw. wt*f is // tail starts here
-
-
redhatcoder 9 years ago this is no different from second challenge of day 1!
-
PRASHANTB1984 9 years ago it isn't, but the idea is to introduce people to objects without throwing in too many new things into the picture
-
pathaksidd 9 years ago I'm very much familiar with programming but even I was very confused at first. Yes, the instructions here weren't clear at all, it was all just thrown on face to write console.log() where you get confused at first thinking "Is this really what you want??"
-
-
-
giacgbj 9 years ago I just wrote:
console.log(myObject);
and it works, but that's not what the problem asked for.
I'm a bit confused :-D
-
mariusgarbea 9 years ago it's right. you already have your type, model, color fields of myObject assigned.
-
giacgbj 9 years ago The task is:
Assign these values to an object car that has the properties type, model and color appropriately and print the object.
There's no object "car" in the code provided (it's called "myObject") and I have nothing to assign, because it's already assigned.
I call it confusing, because the interesting part of the task is already solved at lines 14-18 and you have only to print the result. It's not different from the "Hello World!" of the firsta day.
-
mariusgarbea 9 years ago well, here's my function. it is redundant but does what they want
function printObjectProperty(myObject) { var car = {type:myObject.type, model:myObject.model, color:myObject.color}; console.log(car); }
-
-
medianocturne1 9 years ago The reflex move is to 'define a new object for yourself, and call it 'car', then log 'car' to the console. This is what everyone seems to have expected. For some reason, this is not what they wanted. They apparently wanted to a) confuse new coders who, up until now, felt pretty good about things; and b) have new coders somehow glean from the provided code how object properties are assigned via that function/proto.. and then log to console said object, which is NOT called car, despite what you were told.. but a generic myObject.. The HRank guy said, 'we wanted to show Objects w/o throwing too much at new coders'.. they did the opposite by confusing the new coder, and never having mentioned functions (not to mention anonymous ones) OR prototypes. Not shocking this forum is filled to the brim. That should be all the proof HRank needs that they should revise this question.
-
-
gbrova 9 years ago I agree, the instructions are confusing! Looks like the prepopulated code already solves the problem for us, at lines 14-18.
-
Sort 50 Discussions, By:
Please Log In in order to post a comment