Welcome to Interactive Programming Forums, where you can ask questions, receive answers from other members of the community, post code snippets and post exercies.

What is wrong in this JavaScript code?

+6 votes
What is wrong in this Javascript code? It appears under the Arrays tutorial, question 10

var beverages=new Array("Coke","Sprite","7-UP","Pepsi"); document.write(beverages.unshift("Diet Coke"));

I saw a post dated 2 weeks ago where popo12(6,110 points) said he/she had answered the question but the response does not show up.  HELP!!
posted 5 years ago in Javascript by Heidi Vincent (3,970 points)

1 Answer

+2 votes
Hi,

Can you give me more details about the issue?

I've tried the exercise and got the following result:

js> var beverages=new Array("Coke","Sprite","7-UP","Pepsi");
var beverages=new Array("Coke","Sprite","7-UP","Pepsi");
js> document.write(beverages.unshift("Diet Coke"));
5

Is your output different from mine?
answered 5 years ago by codeadmin (113,880 points)
Thanks, you have the right code but I think you have the wrong answer.  Isn't the "unshift" supposed to place Diet Coke at the beginning of the array? In any case, when I input the code it just repeats itself three times but does not yield a result or allow me to move on to the next question.  So I am stuck.
I copied your code into the exercise box and didn't get anything out of it. no answer no nothing.
I am having the same issue, no response other than repeat itself. Some previous instructions showed same behaviour. All in javascript tutorial. Is there any answer from the site?

Related questions

+6 votes
1 answer
posted 5 years ago in HTML by rahmahnerkhan (1,580 points)
+8 votes
1 answer
posted 5 years ago in Javascript by manlink2000 (5,280 points)
+10 votes
0 answers
posted 5 years ago in Javascript by resila01 (1,700 points)
+7 votes
1 answer
posted 5 years ago in Javascript by Heidi Vincent (3,970 points)
+11 votes
1 answer
posted 6 years ago in Javascript by Idalecio Joaquim (710 points)