Skip to content

AnnaErshova/inflation-calculator.js-web-0615-public

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

language tags type resources
JavaScript, js
selectors, jquery, ajax, json, api, getJSON
lab
5

jQuery Inflation Calculator

inflated dollar

Note

This lab uses both Capybara and Jasmine tests. To run the Jasmine tests, type learn or learn -b. To run the Capybara tests, type rspec. Get all the Jasmine tests to pass before running the Capybara suite.

Background

In economics, inflation can be defined as a general increase in prices and fall in the purchasing value of money.

Objective

You'll be using JavaScript to make an inflation calculator. It will use jQuery to fetch the user's input in the three input fields (start date, end date, start price), and using those values, query an API using jQuery's getJSON method. You will then add this value to the input with an id of endPrice.

Right click on the link below and select "Save link as..." to see a video of how your calculator should behave.

inflation calc vid

jQuery's getJSON function

jQuery's getJSON funtion is just a shorthand for it's ajax function.

Let's take a look at using getJSON to fetch today's weather predictions from Open Weather Map.

var apiUrl = "http://api.openweathermap.org/data/2.5/weather?";

$.getJSON(apiUrl, {
  q: 'New York',
  units: 'imperial'
}).done(function (data) {
  var weather = data.weather[0].description;
  console.log(weather);
});

The above JavaScript queries OpenWeather for the today's weather report for New York City and wants the measurements in imperial units. After fetching the data, it would then log "broken clouds" to the console on a slightly cloudy day or "sunny" and a cloudless summer's day.

Inflation API

In this lab, you'll be hitting Stat Bureau's Inflation API. Take a look at its docs.

Instructions

You'll be modifying only two files:

  1. public/javascripts/inflation-calculator.js
  2. public/javascripts/on-click.js

You'll put all the functions you write in inflation-calculator.js and all the code that must happen within a jQuery .ready() function inside on-click.js (hint: it might be an .on("click", ...) event handler function)

Testing

As noted at the top, this lab uses both Capybara and Jasmine to test the JavaScript. Start by passing all the Jasmine tests (run your testing suite using learn or learn -b). Then run rspec to run the Capybara tests. Get all Jasmine tests passing before you run the Capybara tests.

Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published