Loops in array n loop


#1

1.

Let's replace your current code with a loop.

Write a for loop that loops through your vacationSpots array.

Inside the block of the for loop, use console.log to print each item in the vacationSpots array.

var vacationSpots = ['jsr', 'ngp', 'Barcelona','saagr','sd'];

for (var i = 0; i < vacationSpots.length; i++)
{
  console.log( vacationSpots[i]);
}

can someone tell me ..what is wrong with the code


#2

What error are you getting?


#3
Write a function called nameString()
It should take name as a parameter.
The function returns a string equal to "Hi, I am" + " " + name.
Call nameString() by passing it your name, and use console.log to print the output.

var nameString = function(name)
{
console.log("Hi, I am" + " " + name);

}
nameString('sagar');

what is wrong here?


#4

You are forgetting the period maybe?

Try:
console.log("Hi, I am" + " " + name + ".");