'How do I Create Objects with a Prompt?

The question says it all. Is it even possible for the user to create new objects by responding to a prompt? And if it is possible, then could I also add properties to those objects? (Instructions on this, too, please.

The reason why I'm asking this is because I'm currently doing a school project involving a small database showing our understanding of objects, arrays, and such. I'm not very experienced in Javascript, so a somewhat straightforward answer would be great.

I've noticed a lot of the responses from people on this site include parts of Javascript I don't understand / haven't learned yet.

Please let me know if I can clarify anything.



Solution 1:[1]

You do it like this:

var answer = prompt('...')
# now create your object however you want
var obj = new MyObject(answer)

Prompt itself can't create any objects, of course. It has only one job and does it well.

Solution 2:[2]

var car = new Object();
car["color"] = prompt("Enter the car color name:");
console.log(car);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sergio Tulentsev
Solution 2 Miguel Campos