gSchool Trivia II

The Rules

You will be split into teams of 3 or 4. Pick a team name!

1 Point for every correct answer

An additional point for being the first to answer

No screaming, yelling, and/or being otherwise annoying

Even if I'm wrong, I'm right ( I decide the points )

The Objectives

Recall descriptions and definitions from memory

Mentally evaluate code

Identify what you do and don't know

Have fun!

Category 1: jQuery

5 Questions

Category 1: jQuery

How do you create a new div element with an ID of "myID" in memory with jQuery?

var div = $("<div id='myId'></div>");

Given the above answer, what next line would you add to add text inside that says "Hello $!"

var div = $("<div id='myId'></div>");
div.text("Hello $!");

Category 1: jQuery

Fill in the commented out portion with some code so that on mouseover the text inside the h1 is logged to the terminal.

$("h1").on('mouseover', function () {
    console.log(/* FILL IN HERE */);
};
$("h1").on('mouseover', function () {
    console.log($(this).text());
};

Category 1: jQuery

With this HTML, begin from #start and write code that will navigate (via jQuery) to #end

<div id="splash-page">
  <div class="page-splash">
    <div class="page-splash-message">
      <hr/>
      <div class="ending-class">      
        <p id="end">End Here!</p>
      </div>
    </div>
    <div class="progress progress-striped active page-progress-bar">
      <div class="bar">
        <p id="start">Start Here!</p>
      </div>
    </div>
  </div>
</div>
$("#start").parents().eq(2).find("#end");

Category 1: jQuery

When you click on "Spinach", nothing will happen right now -- fix the code on the right so that it works for every li!

<section>
  <h1>My Favorite Foods</h1>
  <ul>
    <li>Cake</li>
    <li>Sour Patch Kids</li>
  </ul>
</section>
// replace this code
$("ul li").on("click", function () {
  console.log($(this).text());
});

var $li = $("<li>Spinach</li>");
$("ul").append($li);
$("ul").on("click", "li", function () {
  console.log($(this).text());
});

var $li = $("<li>Spinach</li>");
$("ul").append($li);

Category 2: Functions

7 Questions

Category 2: Functions

var myFn1 = function (num) {
  return num * 3;
}

var myFn2 = function (num, cb) {
  return cb(num);
}

var solution = myFn2(10,myFn1);

What is the value of solution?

var myFn3 = function () {
  return function (num) {
    return num * 5;
  }
}

var myFn4 = function (num, cb) {
  return cb()(num);
}

var solution = myFn4(10, myFn3);

How about now?

var solution = [
 myFn1(2), 
 myFn2(3, myFn1), 
 myFn3()(4)
].reduce(function (prev, next) {
    return prev - next;
});

And now?

30

50

-23

Category 2: Functions

var solution = myFn1;
    
var myFn1 = function () {
  return false;
}

function myFn2 () {
  return true;
}

console.log(solution);

What is going to be logged?

var solution = myFn2;
    
var myFn1 = function () {
  return false;
}

function myFn2 () {
  return true;
}

console.log(solution);

How about now?

undefined

the function for myFn2

Category 2: Functions

function counter (inc) {
  var count = 0;
  
  return function () {
    count += inc;
    return count;
  };
};

var incFive = counter(5);
incFive();
var result = incFive();

What is the value of result?

10

function myFn1 () {
  var list = [];
  return function (name) {
    if ( !list.includes(name) )
      list.push(name);
    
    return list;
  };
}

var addInstructor = myFn1();
addInstructor('Robby');
addInstructor('Robby');
addInstructor('Michael');

var result = addInstructor();

What is the value of result?

["Robby", "Michael", undefined]

Category 3: Array Methods

6 Questions

Category 3: Array Methods

var data = [
  [ 1, 2, 3 ],
  [ 'a', 'b' ],
  [ { z: 11 } ]
];

var result = data.map(function (el) {
  el.reduce(function (prev, curr) {
    return prev + curr;
  });
});

console.log(result);

What is the value of result?

[ undefined, undefined, undefined ]

var data = [
  [ 1, 2, 3 ],
  [ 'a', 'b' ],
  [ { z: 11 } ]
];

var result = data.map(function (el) {
  return el.reduce(function (p, c) {
    return p + c;
  });
});

console.log(result);

Alright, alright, now?

[ 6, 'ab', { z: 11 } ]

Category 3: Array Methods

var people = [
  { first: 'Michael', last: 'Herman' },
  { first: 'Wes', last: 'Reid' }  
];


var myFn = function (data, name) {
  return data.filter(function (el) {
    return el.first === name;
  }).map(function (el) {
    return [el.first, el.last];
  });
}

var result = myFn(people, 'Michael');

What is the value of result?

[["Michael", "Herman"]]

var people = [
  { first: 'Michael', last: 'Herman' },
  { first: 'Wes', last: 'Reid', age: 28 }  
];

var result = people.map(function (el) {
  var obj = {};
  obj[el.first] = Object.keys(el);
  return obj;
});

What is the value of result?

{ "Michael": ["first", "last"],

"Wes": ["first", "last", "age"] }

Category 3: Array Methods

var words = ["ameliorate", 
             "alacrity", 
             "asinine"];

var myFn1 = function(l, data) {
  return data.every(function (el) {
    return el.includes(l);
  });
};

var resultA = myFn1('a', words);
var resultB = myFn1('l', words);

What is resultA & resultB?

true & false

var words = ["ameliorate", 
             "alacrity", 
             "asinine"];

var myFn1 = function(l, data) {
  return data.filter(function (el) {
    return el.split('')
      .some(function (el) {
        return el === l;    
      });
  });
};

var resultA = myFn1('n', words);
var resultB = myFn1('l', words);

What is resultA & resultB?

["asinine"], ["ameliorate", "alacrity"]

Category 4: Definitions

6 Questions

Category 4: Definitions

What does JSONP stand for?

What does CORS stand for?

What does AJAX stand for?

JavaScript Object Notation with Padding

Asynchronous JavaScript and XML

Cross-Origin Resource Sharing

Category 4: Definitions

What is the name of a function that returns new instances of an object?

"When you ________ a function, you get it's return value."

What is the difference between a method and a function?

Constructor Function

Methods are functions attached to Objects

Invoke

Category 5: Unfamiliar Code

13 Questions

let x = (a) => a - 10;
let result = x(11);

What is the value of result?

1

Category 5: Unfamiliar Code

In this section you'll be looking at code you will likely not understand. That's okay!

Use what you do know to try and reason about what the answer might be.

let x = ["a", 3, 10];
let [a, b, c] = x;

let result = b + c;

What is the value of result?

13

let words = ["hello", "es2015"];
const result = words.map((el) => {
  return { el };
});

What is the value of result?

{ el: "hello", el: "es2015" }

Category 5: Unfamiliar Code

In this section you'll be looking at code you will likely not understand. That's okay!

Use what you do know to try and reason about what the answer might be.

(def result (+ (- 10 5) (* 2 3)))

What is the value of result?

11

(defn someFn [x y]
    (+ (+ x x) (+ y y)))
(someFn 5 10)

What will be returned?

30

(map 
  (fn [x] (+ x 1))
  [1,2,3])

What will be returned?

(2 3 4)

Category 5: Unfamiliar Code

In this section you'll be looking at code you will likely not understand. That's okay!

Use what you do know to try and reason about what the answer might be.

for num in range(4, 8):
    print(num)

What will be printed?

4,5,6,7

def keyword_args(**kwargs):
    return kwargs

keyword_args(big="foot", loch="ness")

What will be returned?

{"big": "foot", "loch": "ness"}

map(max, [2, 4, 0], [4, 1, 4])

What will be returned?

[ 4, 4, 4 ]

Category 5: Unfamiliar Code

In this section you'll be looking at code you will likely not understand. That's okay!

Use what you do know to try and reason about what the answer might be.

[ "a", "b", "c" ] << [ 1, 2, 3 ].last

What will be returned

[ "a", "b", "c", 3]

[{ firstName: 'Steve', 
   lastName: 'Rogers' },
 { firstName: 'Bruce', 
   lastName: 'Banner' }].map(&:keys)

What will be returned?

[[:firstName, :lastName], [:firstName, :lastName]]

["ruby", :magic, 42].reject do |w|
  w.class != Symbol
end

What will be returned?

[ :magic ]

Category 5: Unfamiliar Code

In this section you'll be looking at code you will likely not understand. That's okay!

Use what you do know to try and reason about what the answer might be.

What will be returned

Hello world!

Made with Slides.com