workshopper / javascripting

Learn JavaScript by adventuring around in the terminal.
http://nodeschool.io
MIT License
2.86k stars 1.04k forks source link

looping-through-arrays #309

Closed annaragnii closed 3 years ago

annaragnii commented 3 years ago

I wrote:

var pets = ['cat', 'dog', 'rat']

for (let i = 0; i < pets.lenght; i++) { pets[i] = pets + 's' } console.log(pets)

but Javascripting said to me:

O-oh, something isn't working.

But don't panic!

─────────────────────────────────────────────────────────────────────────────

Check your solution:

Solution ===================

[ 'cats', 'dogs', 'rats' ]

Your Attempt ===================

[ 'cat', 'dog', 'rat' ]

Difference ===================

[ 'cats', 'dogs', 'rats' ]

AnshulMalik commented 3 years ago

Can you check this line again pets[i] = pets + 's'

Vishesh-garg18 commented 3 years ago

Try this:

var pets = ['cat', 'dog', 'rat']

for (let i = 0; i < pets.length; i++) { pets[i] = pets[i] + 's' } console.log(pets)