Sunday, 13 July 2014

Loops and arrays II

Instructions:
  1. Create an array called names filled with 5 names.
  2. Write a for loop that prints "I know someone called " followed by names[i]. Make sure there's a space between "called" and the name!
  3. Run your code and the five sentences should print out.
Solve:

var name = ["a","b","c","d","e"];
for(var i=0; i<5; i++)
{
    console.log ("I know someone called "+name[i]);
    }

Output:
I know someone called  a

I know someone called b
I know someone called c
I know someone called d
I know someone called e

 

No comments:

Post a Comment