Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions js/q1.js
Original file line number Diff line number Diff line change
@@ -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])
7 changes: 7 additions & 0 deletions js/q10.js
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions js/q2.js
Original file line number Diff line number Diff line change
@@ -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());
5 changes: 5 additions & 0 deletions js/q3.js
Original file line number Diff line number Diff line change
@@ -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());
6 changes: 6 additions & 0 deletions js/q4.js
Original file line number Diff line number Diff line change
@@ -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());
31 changes: 31 additions & 0 deletions js/q5.js
Original file line number Diff line number Diff line change
@@ -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)
24 changes: 24 additions & 0 deletions js/q6.js
Original file line number Diff line number Diff line change
@@ -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")
30 changes: 30 additions & 0 deletions js/q7.js
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 30 additions & 0 deletions js/q8.js
Original file line number Diff line number Diff line change
@@ -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])
14 changes: 14 additions & 0 deletions js/q9.js
Original file line number Diff line number Diff line change
@@ -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)