Giter VIP home page Giter VIP logo

temperature_converter's Introduction

Exercise: Temperature Converter

Goal: create a program that can convert a temperature in Fahrenheit, Celsius or Kelvin to the other two units.

  • Try the bonus goal if you have extra time!

Setup

  • Create an index.html file
  • Create a script.js file
  • make sure to link the script file in the index.html

PART 1

Instructions

  1. Set the fahrenheit variable to temperature that you get from the user
  2. Below that, write Javascript code that converts fahrenheit to its equivalent Celsius and Kelvin values.
  1. Below that, console.log the starting and converted temperatures.
  2. Repeat steps 1-3 for starting celsius and kelvin temperatures.
  3. Test your program by opening index.html in the browser

Your program will look something like this for each starting temperature...

// Starting temperature
var fahrenheit = //some code here to get user input;

// Conversion code
var fahrenheitToCelsius = ...;
var fahrenheitToKelvin = ...;

// Print to console
console.log( "Fahrenheit: " + ... );
console.log( "Celsius: " + ... );
console.log( "Kelvin: " + ... );

Your command line output will look something like this...

Fahrenheit: STARTING_TEMP F
Celsius: CONVERTED_TEMP C
Kelvin: CONVERTED_TEMP K

Feel free to turn to your tablemates for help!

Bonus

Use conditionals (e.g., if-else statement, switch statement) so that your program only prints out the converted temperatures for one starting value.

The starting temperature should be determined by a 'whichTemp' variable that you instantiate at the beginning of the program, and will contain a value of either "f" (Fahrenheit), "c" (Celsius) or "k" (Kelvin).

PART 2

Using Conditionals, have your code accept either fahrenheit, celsius or kelvin, and out put the other two temp types.

Restructure your program from PART 1 so that when you convert a temperature, that new values are stored in an array. Your array will end up looking something like this...

var fahrenheitTemps = [ STARTING_TEMP, CONVERTED_TEMP_1, CONVERTED_TEMP_2 ];

When you console.log the temperatures, make sure you do that by accessing the values stored in the array.

Bonus 1

Use a for or while loop to print out the conversion results for each temperature. It's OK if you need to simplify your console.log statements and remove strings.

Bonus 2

Using loops, create an interface that continues to ask the user for temp conversions until the user requests to stop.

temperature_converter's People

Contributors

amaseda avatar andrewsunglaekim avatar yinkaagiri 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.