Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nikita js primitive exercise #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
15 changes: 15 additions & 0 deletions js/q1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var friends = [
'Moe',
'Larry',
'Curly',
'Jane',
'Emma',
'Elizabeth',
'Elinor',
'Mary',
'Darcy',
'Grey',
'Lydia',
'Harriet'
];
console.log(friends[friends.length - 1]);
3 changes: 3 additions & 0 deletions js/q10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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];

console.log(ages[Math.round(ages.length / 2)]);
17 changes: 17 additions & 0 deletions js/q2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var friends = [
'Moe',
'Larry',
'Curly',
'Jane',
'Emma',
'Elizabeth',
'Elinor',
'Mary',
'Darcy',
'Grey',
'Lydia',
'Harriet'
];

var sortedFriends = friends.sort();
console.log(sortedFriends);
5 changes: 5 additions & 0 deletions js/q3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var friends = 'Moe,Larry,Curly,Jane,Emma,Elizabeth,Elinor,Mary,Darcy,Grey,Lydia,Harriet';
var friendsArray = friends.split(',');
// console.log(friendsArray);
var sortedFriends = friendsArray.sort();
console.log(sortedFriends);
7 changes: 7 additions & 0 deletions js/q4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var friends = 'Moe,Larry,Curly,Jane,Emma,Elizabeth,Elinor,Mary,Darcy,Grey,Lydia,Harriet';
var friendsArray = friends.split(',');
// console.log(friendsArray);
var sortedFriends = friendsArray.sort();
// console.log(sortedFriends);
var reverseFriends = sortedFriends.reverse();
console.log(reverseFriends);
30 changes: 30 additions & 0 deletions js/q5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@


var myFriends = [
'Rickon',
'Meera',
'Hodor',
'Jojen',
'Osha',
'Rickard',
'Maester',
'Rodrik',
'Jory',
'Septa',
'Jon'
];

var yourFriends = [
'Bilbo',
'Boromir',
'Elrond',
'Faramir',
'Frodo',
'Gandalf',
'Legolas',
'Pippin'
];

var ourFriends = myFriends.concat([yourFriends]);
var sortedFriends = ourFriends.sort();
console.log(sortedFriends);
27 changes: 27 additions & 0 deletions js/q6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@



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'
];

var phoIndex = 1 + foods.indexOf('Pho');
console.log(phoIndex);
27 changes: 27 additions & 0 deletions js/q7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

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'
];

var donIndex = foods.indexOf('Donuts');
var foodsAmended = foods.splice(donIndex, 1);
// console.log(foodsAmended);
console.log('New list of fav foods: ' + foods);
25 changes: 25 additions & 0 deletions js/q8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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'
];
var donIndex = foods.indexOf('Donuts');
var foodsAmended = foods.splice(donIndex, 1);
var foodFifthToTenth = foods.slice(4, 11);
console.log(foodFifthToTenth);
21 changes: 21 additions & 0 deletions js/q9.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

//
// 'Moe' is 18
// 'Larry' is 19
// 'Curly' is 20
// 'Jane' is 20
// 'Emma' is 21
// 'Elizabeth' is 18
// 'Elinor' is 23
// 'Mary' is 25
// 'Darcy' is 24
// 'Grey' is 18
// 'Lydia' is 24
// 'Harriet' is 18

var person = {
name: 'Moe',
age: 18
};

console.log(person.name + ' is ' + person.age);
Loading