Git Product home page Git Product logo

theonequiz's Introduction

One Quiz to Rule Them All

Instructions:

Fork this repository into your Github account. Any questions that require you to answer in your own words, but not write code (e.g. question 12) just edit this README with your answer.

Setup

cd lib && bower install
cd ..
http-server

Basics

For this section, I wrote some starter DOM elements in the index.html file.

  1. Write a selector that selects only the first sibling li elements.
  2. Make all li elements behave as inline elements.
  3. Only the odd section elements should have a border.
  4. Only the even li elements should have a lime background.
  5. Only the first aside element in the 2nd section should have blue font color.
  6. There are three div elements with instructions inside them about which side of the screen they should be displayed on. Follow those instructions.
  7. Using vanilla JavaScript, update the HTML of the element with the id of vanilla_output with the following text: "This content generated with vanilla JavaScript".
  8. Using jQuery, update the HTML of the element with the id of jquery_output with the following text: "This content generated with jQuery".

JavaScript concepts

  1. Explain what hoisting is. Provide your answer below.

**Student answer:**A JavaScript feature that allows you to make forward references to functions and variables.

  1. What is a callback? Why do we use them in JavaScript? Provide your answer, and code a simple example below.

**Student answer: **A callback is a function that is passed to another function as an argument. They are used for a variety of reasons, but are very helpful when attempting to communicate data across modules.

$("#btn_1").click(function() {
  alert("Btn 1 Clicked");
});

Functions and operators

In main.js do the following:

  1. Write a function named modulus that takes two arguments. The function should use the modulo operator to return the remainder between the first and second arguments. e.g. modulus(10, 3) // Should return 1.
  2. Write a function named doMath. This function takes three arguments. The first two will contain integer values. The third argument will be a function reference. Write two more functions named add and subtract. Execute the doMath function to add two numbers together. Then execute the doMath function to subtract the two numbers.

Arrays

In the main.js, I started you off with a simple array.

  1. Write a function named sortedPlanets that returns an array of the planet names sorted alphabetically.
  2. Write a function named reversedPlanets that returns an array of planet names that are reversed (i.e. "htraE").
  3. Write a function named longPlanets that returns an array containing only the planet names that are 7 characters long, or longer.

IIFE

  1. In the file named IIFE.js. Write an IIFE that defines a global variable named FruitMaker. It should contain a private array holding the following strings: "apples", "bananas", "cherries", "huckleberries".
  2. The IIFE should expose in its public interface a getter named getFruits() that returns all fruits, and a setter named addFruit() that provides the ability to add a new fruit to the array.
  3. In the file named AugmentedIIFE.js, augment FruitMaker with a function named slices() that accepts two arguments: the name of the fruit, and the number of slices to make. It should return an array containing the name of the fruit duplicated how ever many slices was requested.

For example: slices("apples", 2) should return ["apples", "apples"]

XHR

  1. Write a function named getAnimals that uses the jQuery ajax method to retrieve the data/animals.json file. When you execute the functions, it should just log just the array of animals to the console when the async is complete. Make sure you provide a prompt of "animals" when logging the array.

  2. What are the four HTTP verbs that you can use in an XHR that correspond to the CRUD actions (create, read, update, delete)? **Student answer:**GET, POST, PUT, DELETE

  3. Why did we use Promises when dealing with asynchronous XHR calls? **Student answer:**So that call backs weren't necessary for speaking across modules

  4. Provide a simple example of the syntax for handling a Promise. Student answer:

  var newPromise = promise; 
  newPromise.then(function(data){ 
  console.log(data); 
  })
  .fail(function(err){ 
  console.log(err); }) 
  .done();

Scope and this

What gets logged to the console when the following code executes? Explain why.

**Student answer: **42 is logged to the console because the key word "this" refers to the original call site in the global scope, and answer is defined as 42 in that scope

var answer = "42";

function steve() {
  luke();
}

function luke() {
  var answer = "0";
  greg(answer);
}

function greg(answer) {
  var answer = "666";
  console.log( this.answer );
}

steve();

theonequiz's People

Contributors

stevebrownlee avatar tannert44 avatar luketlancaster avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.