1 year ago

#364209

test-img

Bookit69420

Trouble using a prompt with object literal (JS)(New to coding)

I'm new to coding and JS so I'm sorry if this is a dumb question. I have an object literal named listA, which has various keys:values in it. I am trying to have the code prompt to the user all of the items (keys:values) in the object literal, and allow the user to input a response, which would get stored in another variable.

First off, I have the object literal to start off with:

var listA = {
"Pizza" : 15,
"Salad" : 5,
"Fries" : 6,
"Soda" : 2
};

I've tried many things all along the lines of:

var choice = prompt("What do you want?  \n" + listA);

This was in hopes it would prompt the user all of the items ("Pizza" : 15, "Salad" : 5,"Fries" : 6,"Soda" : 2,) and the user would input a response.

The exact problem is that whenever the code goes to prompt, it prompts [object] instead of all of the items inside the object literal (\\ the menu items) enter image description here

(\\the image above is what exactly it is currently prompting to the user, which is the problem I'm trying to fix)

*Sorry if I didn't ask the question great and/or didn't use stack overflow correctly, I'm new to coding (JS), and stack overflow

javascript

arrays

object

prompt

0 Answers

Your Answer

Accepted video resources