diff --git a/js/q1.js b/js/q1.js new file mode 100644 index 0000000..50943ad --- /dev/null +++ b/js/q1.js @@ -0,0 +1,17 @@ +//1.) Find the last name in the following array: +var friends = [ + 'Moe', + 'Larry', + 'Curly', + 'Jane', + 'Emma', + 'Elizabeth', + 'Elinor', + 'Mary', + 'Darcy', + 'Grey', + 'Lydia', + 'Harriet' +]; + +console.log(friends[friends.length-1]) diff --git a/js/q10.js b/js/q10.js new file mode 100644 index 0000000..33a9b4b --- /dev/null +++ b/js/q10.js @@ -0,0 +1,7 @@ +var ages = [83, 53, 37, 29, 60, 30, 66, 19, 59, 41, 9, 64, 19, 80, 24, 53, 70, 1, 53, 40, 92, 4, 71, 65, 8, 2, 51, 80, 94, 37, 80, 64, 19, 6, 14]; +var level = ages.sort() +//console.log(level) + +var midvalue = Math.round(level.length/2) +var mean = level[midvalue] +console.log(mean) diff --git a/js/q2.js b/js/q2.js new file mode 100644 index 0000000..f2feb4e --- /dev/null +++ b/js/q2.js @@ -0,0 +1,17 @@ +//2.) Sort the list of friends above in alphabetical order. +var friends = [ + 'Moe', + 'Larry', + 'Curly', + 'Jane', + 'Emma', + 'Elizabeth', + 'Elinor', + 'Mary', + 'Darcy', + 'Grey', + 'Lydia', + 'Harriet' +]; + +console.log(friends.sort()); diff --git a/js/q3.js b/js/q3.js new file mode 100644 index 0000000..a7b25e8 --- /dev/null +++ b/js/q3.js @@ -0,0 +1,5 @@ +//3.) There is a list of names in a string below. How could we sort them alphabetically? Hint: use string and array methods. + +var friends = 'Moe,Larry,Curly,Jane,Emma,Elizabeth,Elinor,Mary,Darcy,Grey,Lydia,Harriet'; +var alphaFriends = friends.split(",") +console.log(alphaFriends.sort()); diff --git a/js/q4.js b/js/q4.js new file mode 100644 index 0000000..8b5856b --- /dev/null +++ b/js/q4.js @@ -0,0 +1,6 @@ + //List all the friends above in reverse alphabetical order. + + var friends = 'Moe,Larry,Curly,Jane,Emma,Elizabeth,Elinor,Mary,Darcy,Grey,Lydia,Harriet'; + var alphaFriends = friends.split(",") + var sortF = (alphaFriends.sort()); + console.log(sortF.reverse()); diff --git a/js/q5.js b/js/q5.js new file mode 100644 index 0000000..16091de --- /dev/null +++ b/js/q5.js @@ -0,0 +1,31 @@ + //We have two lists of friends below. Combine the two arrays into one array, then sort them alphabetically. + + var myFriends = [ + 'Rickon', + 'Meera', + 'Hodor', + 'Jojen', + 'Osha', + 'Rickard', + 'Maester', + 'Rodrik', + 'Jory', + 'Septa', + 'Jon' + ]; + + var yourFriends = [ + 'Bilbo', + 'Boromir', + 'Elrond', + 'Faramir', + 'Frodo', + 'Gandalf', + 'Legolas', + 'Pippin' + ]; + + var container = myFriends.concat(yourFriends) + var sorted = container.sort() + +console.log(sorted) diff --git a/js/q6.js b/js/q6.js new file mode 100644 index 0000000..5f5ddc3 --- /dev/null +++ b/js/q6.js @@ -0,0 +1,24 @@ +//6.) I have a list of favorite foods below. If Popcorn is my favorite food and Potato chips my second favorite, then how would you find the rank of another food? Try finding the rank of Pho +var foods = [ + 'Popcorn', + 'Potato chips', + 'Shrimp', + 'Chicken rice', + 'Poutine', + 'Tacos', + 'Toast', + 'French Toast', + 'Crab', + 'Pho', + 'Lasagna', + 'Brownie', + 'Lobster', + 'Donuts', + 'Ice cream', + 'Hamburger', + 'Sushi', + 'Chocolate', + 'Pizza' +]; + +console.log(foods.indexOf("Pho") + "th favourite") diff --git a/js/q7.js b/js/q7.js new file mode 100644 index 0000000..feb4edb --- /dev/null +++ b/js/q7.js @@ -0,0 +1,30 @@ +//6.) I have a list of favorite foods below. If Popcorn is my favorite food and Potato chips my second favorite, then how would you find the rank of another food? Try finding the rank of Pho +var foods = [ + 'Popcorn', + 'Potato chips', + 'Shrimp', + 'Chicken rice', + 'Poutine', + 'Tacos', + 'Toast', + 'French Toast', + 'Crab', + 'Pho', + 'Lasagna', + 'Brownie', + 'Lobster', + 'Donuts', + 'Ice cream', + 'Hamburger', + 'Sushi', + 'Chocolate', + 'Pizza' +]; + +// console.log(foods.indexOf("Pho") + "th favourite") + +var x = foods.indexOf("Donuts") +var y = foods.splice(x,1) + +console.log(x) +console.log(foods) diff --git a/js/q8.js b/js/q8.js new file mode 100644 index 0000000..4bc0a4d --- /dev/null +++ b/js/q8.js @@ -0,0 +1,30 @@ +//8.) My friends want to know what my 5th to 10th favorite foods are. How would I find these foods? +var foods = [ + 'Popcorn', + 'Potato chips', + 'Shrimp', + 'Chicken rice', + 'Poutine', + 'Tacos', + 'Toast', + 'French Toast', + 'Crab', + 'Pho', + 'Lasagna', + 'Brownie', + 'Lobster', + 'Donuts', + 'Ice cream', + 'Hamburger', + 'Sushi', + 'Chocolate', + 'Pizza' +]; + + +for (var i = 4; i < 10; i++) { + console.log (foods[i]) +} + +// console.log(foods[4]) +// console.log(foods[9]) diff --git a/js/q9.js b/js/q9.js new file mode 100644 index 0000000..b4d93f5 --- /dev/null +++ b/js/q9.js @@ -0,0 +1,14 @@ + const obj = [{person:'Moe', age:18}, + {person:'Larry', age:19}, + {person:'Curly', age:20}, + {person:'Jane', age:20}, + {person:'Emma', age:21}, + {person:'Elizabeth', age:18}, + {person:'Elinor', age:23}, + {person:'Mary', age:25}, + {person:'Darcy', age:24}, + {person:'Grey', age:18}, + {person:'Lydia', age:24}, + {person:'Harriet', age:18} ] + +console.log(obj)