JavaScript
SYNTAX:var array = ["one", "two", "three"] for (var i = 0; i < array.length; i++) { do something; }
var array = ["one", "two", "three"] for (var i = 0; i < array.length; i++) { console.log(array[i] + " pineapple(s)"); }
by Sarah Ing + Jessie Wu
Example: given ["one", "two", "three"]
Output =>
one pineapple(s)
two pineapple(s)
three pineapple(s)
Example: given numbers 0 through 10, find the odd numbers.
Output =>
1
3
5
7
9
Example: given it's your birthday, get the even number of pina colada drinks (excluding 0 since no person can resist drinking 0 pina colada drink on their birthday).
Output =>
I can drink 2 pina colada drinks.
I can drink 4 pina colada drinks.
I can drink 6 pina colada drinks.
I can drink 8 pina colada drinks.
I can drink 10 pina colada drinks.
JavaScript
SYNTAX:var array = ["one", "two", "three"] for (var i = 0; i < array.length; i++) { do something; }
var array = ["one", "two", "three"] for (var i = 0; i < array.length; i++) { console.log(array[i] + " pineapple(s)"); }
JavaScript
SYNTAX:for (var i = 0; i < array.length; i++) { if (conditional statement) { do something; } }
var array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] for (var i = 0; i < array.length; i++) { if (array[i] % 2 != 0) { console.log(array[i]); } }
JavaScript
SYNTAX:var counter = starting value while (true statement) { do something; counter increment; }
var number = 2; while (number <= 10) { console.log("I can drink " + number + " pina colada drinks."); number+=2; }
Ruby
SYNTAX:array.each {|variable| do something}
array = ["one", "two", "three"] array.each {|number| puts number + " pineapple(s)"}
Ruby
SYNTAX:for i in 0..n do something end
for i in 0..10 do puts i if i % 2 != 0 end
Ruby
SYNTAX:counter = starting value while(true statement) counter increment do something end
number = 2 while number <= 10 number += 2 puts "I can drink " + number.to_s + " pina colada drinks." end