Extra Practice
Remember: Learning to program takes practice! It helps to see concepts over and over, and it's always good to try things more than once. We learn much more the second time we do something. Use the exercises and additional self-checks below to practice.
1. Data Types and Variable Assignment
let score = 42;
let quote = "Move fast and break stuff.";
let fruits = ['apple', 'orange', 'pear'];
let foo,
bar,
baz;
let stopLoop = false;
let userRegistered = true;
What is the name of the String variable above?
fruitsscorequotefooquote.What Data Type is score?
score variable is a Number.What does fruits.length equal?
fruits.length equals 3.What are foo, bar, and baz equal to?
0''nullundefinedfoo, bar, and baz are equal to undefined because they have been declared but not initialized.What is it called when we name a variable without setting a variable (as with foo, bar, and baz in the code above)?
undefined until it is initialized.What Data Types are stopLoop and userRegistered?
baz is equal to undefined because we cannot multiply two Strings.2. JSON Interpretation
let weatherData = {
"city": {
"id": 5809844,
"name": "Seattle",
"coord": {
"lon": -122.3321,
"lat": 47.6062
},
"country": "US",
},
"list": [
{
"dt": 1500148800,
"temp": {
"day": 74.05,
"min": 55.96,
"max": 75.09,
"night": 55.96,
"eve": 69.6,
"morn": 68.9
},
"pressure": 1024.13,
"humidity": 51,
"weather": [
{
"id": 800,
"main": "Clear",
"description": "sky is clear",
"icon": "01d"
}
],
"speed": 5.17,
"deg": 222,
"clouds": 0
},
{
"dt": 1500235200,
"temp": {
"day": 67.3,
"min": 55.78,
"max": 68.94,
"night": 56.08,
"eve": 65.71,
"morn": 55.78
},
"pressure": 1026.81,
"humidity": 57,
"weather": [
{
"id": 800,
"main": "Clear",
"description": "sky is clear",
"icon": "01d"
}
],
"speed": 3.38,
"deg": 353,
"clouds": 0
},
{
"dt": 1500321600,
"temp": {
"day": 69.85,
"min": 52.63,
"max": 70.54,
"night": 52.63,
"eve": 66.49,
"morn": 58.32
},
"pressure": 1019.85,
"humidity": 51,
"weather": [
{
"id": 801,
"main": "Clouds",
"description": "few clouds",
"icon": "02d"
}
],
"speed": 6.71,
"deg": 357,
"clouds": 12
}
]
}
The data above represents a three-day weather forecast for Seattle, WA. Use this data structure to answer the questions below.
What is the Data Type of the weatherData.city property above?
weatherData.city is an Object.What Data Type is weatherData.list?
weatherData.list is an Array.What does weatherData.list.length equal?
weatherData.length equals 3.What does weatherData.list[1].humidity equal?
58.32515775.3weatherData.list[1].humidity equals 57.What does weatherData.list[0].temp.eve equal?
56.769.678.382.1weatherData.list[0].temp.eve equals 69.6.What is the Data Type of weatherData.list[2].weather[0].main?
weatherData.list[0].weather[0].main is a String.What is the Data Type of weatherData.list[2].weather?
weatherData.list[0].weather is an Array.Visit Content Online
The content on this page has been removed from your PDF or ebook format. You may view the content by visiting this book online.