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

js-1 afternoon #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
73 changes: 68 additions & 5 deletions practice.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,28 @@ function greeting(name) {

//Code Here

const newGreeting = function (name) {
return `Hello, ${name}`
}

//////////////////PROBLEM 3////////////////////

//Rewrite the function greeting as an arrow function.
//Name it finalGreeting.

//Code Here

const finalGreeting = (name) => `Hello, ${name}`;

//////////////////PROBLEM 4////////////////////

//Create an array called groceries with the values
//"apples", "milk", "eggs", "bread"

//Code Here

const groceries = ['apples', 'milk', 'chocolate', 'eggs', 'bread', 'chocolate'];

//Write a function called doubleCheck that takes in an array
//as a parameter.

Expand All @@ -39,6 +47,24 @@ function greeting(name) {

//Code Here

const doubleCheck = function (arr) {
let chocolate = false;
arr.forEach((e,i,a) => {

e === 'chocolate'
? chocolate = true
? a.splice(i,1)
: chocolate = true
: null;

})

!arr.includes('chocolate') ? arr.push('chocolate') : null;
return arr;
}

doubleCheck(groceries);

//////////////////PROBLEM 5////////////////////

//Create an object saved to the variable dog.
Expand All @@ -48,20 +74,33 @@ function greeting(name) {

//Code Here

var dog = {
name: 'unicorn',
color: 'all the colors of the rainbow',
age: 7,
goodBoy: true
};

//...access the dog's name from the object and assign it to a
//variable called devMountainClassPet.

//Code Here

var devMountainClassPet = dog.name;

//Add a method to dog called bark.
//The value of bark should be a function that returns the string "Woof woof".

//Code Here

dog.bark = () => 'Woof woof';

//Store the result of invoking the bark method in a variable called ruff.

//Code Here

var ruff = dog.bark();

//////////////////PROBLEM 6////////////////////

//Write a function called looper that takes in an array. looper should declare
Expand All @@ -75,6 +114,16 @@ function greeting(name) {

//Code Here

const looper = (arr) => {
return arr.reduce((a,b) => b%2 === 1 || b >= 100 ? a += b : a)

// let mySum = 0;
// arr.forEach(e => e%2 === 1 || e >= 100 ? mySum += e : null);
// return mySum;
}

// console.log(looper([1, 2, 3, 5, 100, 1000, 6]));

//////////////////PROBLEM 7////////////////////

//Given the following function called math
Expand All @@ -88,14 +137,18 @@ function math(num1, num2, callback) {

//Code Here

const add = (n1, n2) => n1 + n2;

//Now invoke math, passing in the numbers 3 and 4, and your add function,
//storing the result in the variable mathSum.

//Code Here

let mathSum = add(3, 4);

//////////////////PROBLEM 8////////////////////

//Write a function called invoker that takes in one paramter, a callback function.
//Write a function called invoker that takes in one parameter, a callback function.
//invoker should return the result of invoking the callback.

function sampleCallbackOne() {
Expand All @@ -108,6 +161,10 @@ function sampleCallbackTwo() {

//Code Here

function invoker(cb) {
return cb();
}

//////////////////PROBLEM 9////////////////////

let duck = "cute";
Expand All @@ -130,16 +187,16 @@ function pond() {
//as strings.

//This array should contain the variable names (as strings) accessible in the global scope.
let globalScope = ["duck", "sailorDuck", "rubberDuck", "realDuck"];
let globalScope = ["duck"];

//This array should contain the variable names (as strings) accessible in the bathroom function.
let bathroomScope = ["duck", "sailorDuck", "rubberDuck", "realDuck"];
let bathroomScope = ["duck", "rubberDuck"];

//This array should contain the variable names (as strings) accessible in the bathtub function.
let bathtubScope = ["duck", "sailorDuck", "rubberDuck", "realDuck"];
let bathtubScope = ["duck", "sailorDuck", "rubberDuck"];

//This array should contain the variable names (as strings) accessible in the pond function.
let pondScope = ["duck", "sailorDuck", "rubberDuck", "realDuck"];
let pondScope = ["duck", "realDuck"];

//////////////////PROBLEM 10////////////////////

Expand All @@ -148,10 +205,16 @@ let pondScope = ["duck", "sailorDuck", "rubberDuck", "realDuck"];

//Code Here

const outerFn = () => () => 'Shaun';

//Now save the result of invoking outerFn into a variable called innerFn.

//Code Here

const innerFn = outerFn();

//Now invoke innerFn and save the result to a variable called finalResult.

//Code Here

const finalResult = innerFn();