-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs-warm-ups.html
More file actions
111 lines (91 loc) · 3.14 KB
/
js-warm-ups.html
File metadata and controls
111 lines (91 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Morning JS Warm Ups</title>
</head>
<body>
<h1>Morning JS Warm Ups</h1>
<script>
"use strict";
//---- Warm up 5.9 ----
// Write a function that accepts an array of numbers and returns the average.
//
// function average(array) {
// var total = 0;
// for (var i = 0; i < array.length; i++) {
// total += array[i];
// }
// return total / array.length;
// }
//
// console.log(average([3, 5, 7, 10, 0]));
// // 5
//---- Warm Up 5.10 ----
// Write a function, calculateTotalStudents, that returns the total number of students recorded in the classes array.
// let classes = [
// {class: "6th grade history", students: 18},
// {class: "7th grade history", students: 20},
// {class: "8th grade history", students: 22}
// ];
//
// function calculateTotalStudents(arrayOfObjects){
// var totalStudents = 0;
// for (var i = 0; i < classes.length; i++ ){
// totalStudents += classes[i].students;
// }
// return totalStudents;
// }
// ---- WARM UP 5.11 ----
// Write a function called convertToObject that takes in a string that is the name of a class, and a number that is the number of students, and returns an object with the properties `class` and `students`
//convertToObject("Intro to Programming", 20) returns {class: "Intro to Programming", students: 20}
function convertToObject(string, number){
return {class: string, number: number};
}
var neighborhood1 ={
neighborhood: "Lovely Estates",
medianHomePrice: 280000,
pool: true,
tennis: false,
crimeRate: "low",
schools: [
{name: "ES1", rating: 8},
{name: "MS2", rating: 6},
{name: "HS3", rating: 8}
]
}
var neighborhood2 ={
neighborhood: "Luminous Estates",
medianHomePrice: 270000,
pool: true,
tennis: false,
crimeRate: "low",
schools: [
{name: "ES1", rating: 8},
{name: "MS2", rating: 8},
{name: "HS3", rating: 8}
]
}
var neighborhood3 ={
neighborhood: "Ginormous Ego Estates",
medianHomePrice: 350000,
pool: true,
tennis: true,
crimeRate: "low",
schools: [
{name: "ES1", rating: 9},
{name: "MS2", rating: 9},
{name: "HS3", rating: 9}
]
}
// Write a function that takes a neighborhood object and determines if it is desirable. A neighborhood is desirable if the median home price is less than 300000, crime rates are low, and the total rating of schools is at least 24.
function desirableNeighborhood(neighborhoodObject){
var totalRating = 0;
for (var i = 0; i < neighborhoodObject.schools.length; i++){
totalRating += neighborhoodObject.schools[i].rating;
}
return neighborhoodObject.medianHomePrice < 300000 && neighborhoodObject.crimeRate === "low" && totalRating >= 24;
}
</script>
</body>
</html>