From 7c68904c1821c460154ac614e2c156deffc7c734 Mon Sep 17 00:00:00 2001 From: Nur Hidayah Date: Thu, 21 Sep 2017 00:22:59 +0800 Subject: [PATCH 01/12] q1 and q2 --- js/q1.js | 17 +++++++++++++++++ js/q2.js | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 js/q1.js create mode 100644 js/q2.js 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/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()); From f4fd4c1880daa1ebcd9342fd7beddd93f97562ec Mon Sep 17 00:00:00 2001 From: Nur Hidayah Date: Thu, 21 Sep 2017 00:38:45 +0800 Subject: [PATCH 02/12] qn3 done --- js/q3.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 js/q3.js 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()); From 202a58a4d4f8e4412b8ad873c456a8fa285de461 Mon Sep 17 00:00:00 2001 From: Nur Hidayah Date: Thu, 21 Sep 2017 00:42:34 +0800 Subject: [PATCH 03/12] qn4 --- js/q4.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 js/q4.js diff --git a/js/q4.js b/js/q4.js new file mode 100644 index 0000000..14da872 --- /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()); From 7ce407a766cf40d79026ec2b1a85252a96f670aa Mon Sep 17 00:00:00 2001 From: Nur Hidayah Date: Thu, 21 Sep 2017 00:47:11 +0800 Subject: [PATCH 04/12] qn 5 done --- js/q4.js | 2 +- js/q5.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 js/q5.js diff --git a/js/q4.js b/js/q4.js index 14da872..8b5856b 100644 --- a/js/q4.js +++ b/js/q4.js @@ -1,4 +1,4 @@ -//List all the friends above in reverse alphabetical order. + //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(",") 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) From 51d10bc164fd82d54f592a47ce75a6aa964ec86f Mon Sep 17 00:00:00 2001 From: Nur Hidayah Date: Thu, 21 Sep 2017 00:51:39 +0800 Subject: [PATCH 05/12] q6 --- js/q6.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 js/q6.js 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") From e1300382ee270cce26a7bcc4071394c1e4e03d7f Mon Sep 17 00:00:00 2001 From: Nur Hidayah Date: Thu, 21 Sep 2017 01:03:14 +0800 Subject: [PATCH 06/12] qn7 --- js/q7.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 js/q7.js 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) From 0fb8496f2889ad4f71e957a6a0121546782ffbc8 Mon Sep 17 00:00:00 2001 From: Nur Hidayah Date: Thu, 21 Sep 2017 01:26:33 +0800 Subject: [PATCH 07/12] qn 8 --- js/q8.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 js/q8.js 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]) From 6b8a50f45473704156b172bbcded9edb3adabf07 Mon Sep 17 00:00:00 2001 From: Nur Hidayah Date: Thu, 21 Sep 2017 01:55:56 +0800 Subject: [PATCH 08/12] notsureyet.commit first --- js/q9.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 js/q9.js diff --git a/js/q9.js b/js/q9.js new file mode 100644 index 0000000..c5480b2 --- /dev/null +++ b/js/q9.js @@ -0,0 +1,14 @@ +age = ['Moe': 18, +'Larry': 19, +'Curly': 20, +'Jane': 20, +'Emma': 21, +'Elizabeth': 18, +'Elinor': 23, +'Mary': 25, +'Darcy': 24, +'Grey': 18, +'Lydia': 24, +'Harriet': 18 ] + +console.log(age) From b4f2ebe103b0e5aefe02cdb4393da8088d163263 Mon Sep 17 00:00:00 2001 From: Nur Hidayah Date: Thu, 21 Sep 2017 02:08:08 +0800 Subject: [PATCH 09/12] sorted --- js/q10.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 js/q10.js diff --git a/js/q10.js b/js/q10.js new file mode 100644 index 0000000..34e4319 --- /dev/null +++ b/js/q10.js @@ -0,0 +1,5 @@ +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) + +// From 96aba28f3444b1818942a47f1c2437d9d272b358 Mon Sep 17 00:00:00 2001 From: Nur Hidayah Date: Thu, 21 Sep 2017 09:26:38 +0800 Subject: [PATCH 10/12] assigned values --- js/q9.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/js/q9.js b/js/q9.js index c5480b2..b4d93f5 100644 --- a/js/q9.js +++ b/js/q9.js @@ -1,14 +1,14 @@ -age = ['Moe': 18, -'Larry': 19, -'Curly': 20, -'Jane': 20, -'Emma': 21, -'Elizabeth': 18, -'Elinor': 23, -'Mary': 25, -'Darcy': 24, -'Grey': 18, -'Lydia': 24, -'Harriet': 18 ] + 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(age) +console.log(obj) From 34eb08461c1958aa0e48bd6e0e95b6c9b1e968df Mon Sep 17 00:00:00 2001 From: Nur Hidayah Date: Thu, 21 Sep 2017 09:30:54 +0800 Subject: [PATCH 11/12] q10 mean --- js/q10.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/js/q10.js b/js/q10.js index 34e4319..93b37ae 100644 --- a/js/q10.js +++ b/js/q10.js @@ -2,4 +2,11 @@ var ages = [83, 53, 37, 29, 60, 30, 66, 19, 59, 41, 9, 64, 19, 80, 24, 53, 70, 1 var level = ages.sort() //console.log(level) -// + var total = 0; + for(i=0; i Date: Thu, 21 Sep 2017 09:36:10 +0800 Subject: [PATCH 12/12] q10 --- js/q10.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/js/q10.js b/js/q10.js index 93b37ae..33a9b4b 100644 --- a/js/q10.js +++ b/js/q10.js @@ -2,11 +2,6 @@ var ages = [83, 53, 37, 29, 60, 30, 66, 19, 59, 41, 9, 64, 19, 80, 24, 53, 70, 1 var level = ages.sort() //console.log(level) - var total = 0; - for(i=0; i