Skip to content

Latest commit

 

History

History
100 lines (68 loc) · 1.8 KB

checkpoint.md

File metadata and controls

100 lines (68 loc) · 1.8 KB

Javascript Assessment

Variables

  1. Assign the string "Jack" to a variable called captain

  2. Using the captain variable, use string concatenation to form the string "Oh Jack, my Jack!", assigning it to a variable named phrase

Arrays & Loops

assume to the following array:

var days = ['Thursday', 'Friday', 'Saturday', 'Sunday']
  1. loop through the array to print the following
0 Thursday
1 Friday
2 Saturday
3 Sunday

JS loop

write a loop that print out the following:

16 bananas
14 bananas
12 bananas
10 bananas
8 bananas
6 bananas

Data Structures - JS Objects

assume the following object

var brain = {
  energyLevel: 10
}
  1. write code to add a dream property to the brain object with the string value 'electric sheep'

  2. write code to add a dayDream property to the brain object with the value { lunch: ['burger', 'beer'] }

  3. write code to add 'pudding' to the beginning of the lunch array

Objects

assume to the following object:

var dog = {
  name: 'fluffy',
  age: 4,
  hairColor: 'pink'
}
  1. research the builtin Object.keys() function and use it to console log all the property names as an array

JS Functions

  1. Write a function isOdd that accepts a number as a parameter and return a boolean to indicate wether the number is odd or not

examples of calling the function in the console

> isOdd(2)
< false
> isOdd(3)
< true
  1. Invoke the function with 6 as arguments and save it to a variable named result

bonus

given the following array

var studentYearOfBirths = [2001, 1975, 1992, 1998, 1988, 1994]
  1. write code to calculate the students average age

  2. if you used a for loop solve this again using forEach