Javascript Array structure


var temp = prompt("How many countries have you been to?");
var input = [];
var countryname = prompt("so list country no "+ temp); input.push(countryname);


    for(i = 0; i < input.length; i++){

I made a simple JS code to test my do/while loop and for loop. The premise of the code is to ask the user for "The number of countries he/she has been to" and then have the list the "name of the countries he/she has been to". Finally the snippet prints out the name of the countries in the for loop.

I though I had it covered, But when it prints out the names of the countries. it seems to print out the individual characters of the last entered country name rather than the entire name of the countries. One by one. What have I done wrong ? Stumped. Thank you.




this should be input[i], you store the countries in input. countryname simply contains the entry from the last prompt


Ahhh.. I want to swear at myself. &(*&%&% .. How could I have missed that ? Thank you :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.