Using prompt() to call a method


I was trying to think outside the lesson a bit here, so instead of just typing "20" as the instructions implied, I used:

// here is bob again, with his usual properties
var bob = new Object(); = "Bob Smith";
bob.age = 30;
// this time we have added a method, setAge
bob.setAge = function (newAge){
bob.age = newAge;
// here we set bob's age to 40
bob.setAge(prompt("What is Bob's Age?"));
// bob's feeling old. Use our method to set bob's age to 20

When I type "20" into the prompt, the lesson tells me I did not change Bob's age to 20. Why doesn't this work?


For start, you need to call setAge() twice and set Bob's age to 40, the to 20. And in this lesson, you need to explicitly pass value 20 second time you call the setter. If it wasn't mandatory, you could do that with prompt().