Given this starter change.html (and change.css), implement functionality
such that a user can type in a coin amount in the #amount
text input and
the corresponding US dollar amount for that number of one of four US coins is
displayed. You can find the runnable example here.
In the provided HTML, there are four possible coin value options a user can select: Penny (1 cent), Nickel (5 cents), Dime (10 cents), and Quarter (25 cents). Initially, the default coin selected should be the penny. Whenever either the "Make $$$" button is clicked or one of these coin values is changed, the hidden message should be updated to include information about the total amount of change for the selected coin count and coin type.
To provide a user-friendly experience, ensure that if an input value is negative when a
coin change is being calculated, reset the value to 0 in the input box. If the value
is not entered as an integer, use Math.floor
to round the decimal value
down. In such a case, the calculation should be done with the result value and the
input box should also be changed to include the integer value. Use
toFixed(2)
if needed to format a number to exactly two digits after the decimal.
Make sure to try out our runnable solution for a demonstration of these different cases (without looking at the JS solution!).
Solution: JS
Create a page which contains an animated bouncing all. You are given
ball.html
and
ball.css
and you will write ball.js
(running solution).
You will also need this image, which the provided
ball.html
links to relatively in a path images/voltorb.png
.
ball-area
and use that element's width/height as boundaries.Solution: JS
A furball is on the loose! Rawr! At first glance, he might look cute, fluffy, and
all-around harmless, but the townspeople have a reason to be terrified. Write JavaScript
code to bring Gnar to life, and ultimately let him achieve his true ultimate form. The
HTML
and CSS
are already written. Start from this skeleton of
gnar.html (sample solution).
Make it so that when the page first appears, 5 boys are visible in
the town. There are already 5 persons in the HTML
, but they have no gender.
These are stored in the div
with id
of people
as
divs
with the class
of person
.
<div id="people">
<!-- add your code here -->
<div class="person"></div>
<div class="person"></div>
<div class="person"></div>
<div class="person"></div>
<div class="person"></div>
</div>
HTML
Implement the Add
button functionality so that it adds 5 more boys
to the page. A person is a div
with the classes of person
and a class of either boy
or girl
.
<button id="add">Add!</button>
HTML
Implement the Kill
button functionality so that clicking it will
randomly "kill" 1/5 of the boys on the page. Kill them by giving them a class of
splat
.
<button id="kill">Kill!</button>
HTML
Add functionality to the boy and girl radio buttons with a function that returns which of the two genders is currently selected. Modify the code from your previous two exercises so that you can choose which of the two genders to add and kill.
<label><input id="boys" type="radio" name="gender" /></label>
<label><input id="girls" type="radio" name="gender" checked="checked" /></label>
HTML
Add functionality to the "clean up" button so that it removes any dead "splatted"
people from the page (any div
s with the class splat
).
<button id="cleanup">Clean up!</button>
HTML
Now this is when Gnar shows his true form... Add functionality to the "Beast Mode" button so that Gnar's img
tag and the page's top h1
tag have the class of enrage
applied. In addition, Gnar should be made to be 50px wider than his current width. Clicking the button again removes the class both the img
and h1
tags and returns the width to the previous value. The h1
has an existing CSS
that should not be removed.
<button id="enrage">Beast Mode!</button>
HTML
Finally, add animation functionality to the page! Add a function so that when the
"patrol" button is clicked, Gnar moves right by 4px every 20ms until his
left
position style is at least 300px. Gnar should then immediately
change directions and start patrolling to his left until his left
position is 10px or less, at which he stops patrolling.
<button id="patrol">Patrol</button>
HTML
Add functionality to the "stomp" button so that when clicked, Gnar moves up or down by
75px and also kills 1/5 of both genders on the page. Gnar is an img
tag with an id
of gnar
.
<button id="stomp">Stomp!</button>
HTML
Solution: JS
In this exercise, we will implement a version of "turtles all the way down"
(yes, this is a thing).
The provided squirtles.html
contains the earth, elephant, and a single Squirtle.
Write JavaScript code squirtles.js
to give the page infinitely-scrolling
Squirtles (running solution).
You will need to add a new Squirtle to the bottom of the page every time the user scrolls
to the bottom. To add a Squirtle, append to document.body
a new div
with the class of squirtle
(See slide below for more implementation details).
Use these events and properties to help you implement your solution:
document.onscroll
:
An event that occurs when the user moves the scrollbar
document.body.scrollHeight
:
The height of the entire web page
window.scrollY
:
The number of pixels that we have currently scrolled down from the top of the page
window.innerHeight
:
The height of the visible area of the page currently on-screen
Solution: JS