Code Monkey home page Code Monkey logo

cssi-4-jquery-warmup's Introduction

JQuery Day 4 Warm-up!

Instructions:

Fork and clone this lab, then complete the drills below.

1. Selector Drills

Given the following HTML page:

<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-git.js"></script>
    <title>Fruits</title>
  </head>
  <body>
    <h1>Fruits</h1>    
    <h2 class="div">Orange</h2>
    <div>
      <p>Cherry</p>
      <p id="h2">Banana</p>
    </div>
  </body>
</html>

What would be the output of the following jQuery commands?

$('h1').text();
$('h2').text();
$('#h2').text();
$('.div').text();
$('#div').text();
$(div).text();

Make your guesses before running the code. You can check your answers by opening http://jsbin.com, copying the HTML into the HTML tab, and copying the jQuery commands into the Console tab.

2. Manipulating the DOM

Given the following HTML page:

<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-git.js"></script>
    <script src="animals-script.js"></script>
    <title>SPIRIT ANIMAL</title>
  </head>
  <body>
    <h1>My spirit animal is a:</h1>
    <div id="favorite">bunny</div>
  </body>
</html>

Write JavaScript to do the following:

  1. Log the contents of the div to the console.
  2. Change the text content of the div to be "bear" instead of "bunny"
  3. Change the content of the div to show this picture of a bear instead of text: http://i.imgur.com/SHxgKJv.png

The HTML file and JavaScript stub file are available in this git repository in the directory animals. Put your JavaScript in animals-script.js and load animals.html to test your answers.

3. Event Handlers

Open the contents of cookies/cookies.html in Chrome. You should see something like: cookie monster lab

Modify cookies-script.js and cookies.html to accomplish the following:

  1. Log a message "Baking a cookie" to the console when the "BAKE a cookie" button is clicked.
  2. Implement "BAKE a cookie": Insert an image with source cookie.png into the div with id="plate" when the "BAKE a cookie" button is clicked. You should be able to add multiple cookies into the div.
  3. Implement "EAT ALL the cookies": Remove all the cookies from the pink plate when "EAT ALL the cookies" button is clicked.
  4. Implement "EAT a cookie": Remove a single cookie from the pink plate when the "EAT a cookie" button is clicked.

4. Code reading: Forms and Event handlers

Remember the form in the Deli Counter lab? Now you've learned enough to understand the contents of the index.html and lib/app.js file!

Take some time to look through those files again and describe in English how it works to your neighbor: https://github.com/learn-co-students/js-deli-counter-google-cssi-test-2015

5. Coding: Forms and Event Handlers

Open the contents of todo/todo.html in Chrome. You should see something like: todo lab

Modify todo-script.js and todo.html to accomplish the following:

  1. Log the contents of the text input when the "Add" button is clicked.
  2. Implement "Add": Insert the contents of the text input at the end of the ol list when the "Add" button is clicked. Clear the contents of the text input when this happens.
  3. Implement "Submit on enter": Pressing enter while focused on the text box should trigger the same behavior as clicking the "Add" button.
  4. EXTRA CREDIT Warning: These are both quite tricky due to some jQuery quirks. Only proceed if you're VERY comfortable with everything we've done so far - and comfortable using Google for help!
  • Implement "Cross off": Clicking each list item should cross the item off the list by making it appear with a strike through it.
  • Implement "Delete": Add a "Delete" button next to every item of the list. Clicking this button should remove the item from the list.

6. An Annoying JS Bug

Given the following wontwork.html page:

<!DOCTYPE html>
<html>
  <head>
    <script src="https://code.jquery.com/jquery-git.js"></script>
    <script src="wontwork-script.js"></script>
    <title>Weather Report</title>
  </head>
  <body>
    <h1 id="weather">Rainy :(</h1>
  </body>
</html>

And the following wontwork-script.js file:

function magicWand() {
  $('#weather').text('Sunny!');
}
magicWand();

Answer the following questions:

  1. When you load wontwork.html, what appears in the h1: "Sunny!" or "Rainy :("? Why?
  2. Modifying only wontwork-script.js, how do you fix this bug?

The HTML file and JavaScript stub file are available in this git repository in the directory wontwork.

cssi-4-jquery-warmup's People

Watchers

 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.