Skip to content

Commit b6081ac

Browse files
committed
chapter exercises
1 parent 76ac4e7 commit b6081ac

File tree

3 files changed

+70
-10
lines changed

3 files changed

+70
-10
lines changed
Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,39 @@
1-
let tortoiseOne = {
2-
species: "Galapagos Tortoise",
3-
name: "Pete",
4-
weight: 919,
5-
age: 85,
6-
diet: ["pumpkins", "lettuce", "cabbage"]
7-
};
8-
9-
// Using a for..in loop, iterate through each property in the tortoiseOne object and print the value to the console.
1+
// let tortoiseOne = {
2+
// species: "Galapagos Tortoise",
3+
// name: "Pete",
4+
// weight: 919,
5+
// age: 85,
6+
// diet: ["pumpkins", "lettuce", "cabbage"]
7+
// };
8+
9+
// // Using a for..in loop, iterate through each property in the tortoiseOne object and print the value to the console.
10+
11+
// // let giraffe = {
12+
// // species: "Reticulated Giraffe",
13+
// // name: "Cynthia",
14+
// // weight: 1500,
15+
// // age: 15,
16+
// // diet: "leaves"
17+
// // };
18+
19+
// for (item in tortoiseOne) {
20+
// console.log(item + ',' + tortoiseOne[item]);
21+
// }
22+
// let tortoiseOne = {
23+
// age: 150,
24+
// species: "Galapagos Tortoise",
25+
// diet: ["pumpkins", "lettuce", "cabbage"]
26+
// };
27+
28+
// let tortoiseTwo = {
29+
// age: 150,
30+
// species: "Galapagos Tortoise",
31+
// diet: ["pumpkins", "lettuce", "cabbage"]
32+
// };
33+
34+
// console.log(tortoiseOne == tortoiseTwo);
35+
// console.log(tortoiseOne === tortoiseTwo);
36+
// console.log(tortoiseOne.age === tortoiseTwo.age);
37+
let num = Math.floor(Math.random()*10);
38+
39+
console.log(num);

objects-and-math/chapter-examples/KindnessSelection.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ function randomSelection(arr){
1414
//Experiment with the code above. Try to:
1515
//a) Print 3 random selections from each array.
1616
//b) Have the code randomly pick one array, and then print 2 random items from it.
17-
//c) Create a new array, then fill it with one random item from words and happiness. Print the new array.
17+
//c) Create a new array, then fill it with one random item from words and happiness. Print the new array.
18+
19+
20+
console.log(randomSelection(happiness));
21+
console.log(randomSelection(words));
22+
23+

objects-and-math/exercises/ObjectExercises.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ let salamander = {
1414

1515

1616
// After you have created the other object literals, add the astronautID property to each one.
17+
let monkeyTwo = {
18+
name: "Brad",
19+
species: "Chimpanzee",
20+
mass: 11,
21+
age: 6
22+
};
23+
24+
let doggyOne = {
25+
name: "Leroy",
26+
species: "Beagle",
27+
mass: 14,
28+
age: 5.
29+
};
30+
31+
let specimenOne = {
32+
name: "Almina",
33+
species: "Tardigrade",
34+
mass: .0000000001,
35+
age: 1
36+
};
37+
38+
superChimpOne.astronautID = Math.round()*10
39+
40+
1741

1842
// Create an array to hold the animal objects.
1943

0 commit comments

Comments
 (0)