What key word is used to create a variable in JavaScript?
if (condition) {
code
}
How do I declare an empty array named 'arr'
var arr = []
What are the two types of loops that we learned about?
Name one of the object animals your classmates created (cannot be your own)
Elephant cat, flying shark, Lola, PENUT, eye spring
How do you get the length of a string?
.length
What is the name of a variable that can only take the values true or false
boolean
How do I get the element "code" out of the array:
arr = ["learning", "to", "code", "is", "fun!"]
arr[2]
Why do we use loops?
lots of correct answers
Name 2 types of data in Javascript
Number, string, boolean, array, object
What symbol(s) can I use to return true if ONE or BOTH boolean expressions are true, and false otherwise? ex. expr1 __ expr2
||
How do I add the item 2 to the array
arr =[1, 3, 1]
arr.push(2)
other acceptable answers
Fill in the blanks to declare a for loop that runs 20 times
for (let ____; ____; ____) {
...
for (let i=0; i < 20; i++) {
(multiple correct answers)
Set the 'color' attribute of the object myAnimal to 'green'
myAnimal.color = 'green'
What is the index of the "w" in "Hello world!"
6
What will the following statement print?
If (true || false) {print("Hello ")}
If (true && false) {print("World")}
else {print("!")}
Hello!
Name one way to remove an element from an array
.pop(), .shift(), .slice()
How might I create an infinite loop
ex. while(true)
Declare a new object stored in the variable 'myObject' with the attribute size that takes the value 100
size: 100
}
What function call would I use to get only the "love" out of var s = "I love Javascript!"
s.slice(2, 6)
What will x be equal to at the end of this statement?
x = ""
if (x) {x += "Python"}
if (!x) {x += "JavaScript"}
if (x.length > 6) {x += " is the best"}
else if (x.length < 100) {x += " is the worst"}
else {x += "!"}
JavaScript is the best
how might I combine the following arrays into a single array with all of the names?
var names1 = [“Jennie”, “Rose”]
var names2 = [“Jisoo”, “Lisa”]
var allNames = names1.concat(names2)
Write a loop that adds up every element in an array of numbers 'arr' and stores it in the variable sum. Start with:
sum = 0
for (let i = 0; i < ___; i++) {
}
sum = 0
for (let i = 0; i < arr.length; i++) {
sum += arr[i]
}
Why do we use objects in JavaScript? (Has to be a really good answer for 500 points!)
Answers will vary