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

  • Fork and clone this repo to your computer.
  • Open temp_converter.js.

PART 1

Instructions

  1. Set the fahrenheit variable to a starting temperature.
  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 running $ node temp_converter.js in the command line.

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

// Starting temperature
var fahrenheit = 32;

// 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

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

var fahrenheitTemps = [ STARTING_TEMP, CONVERTED_TEMP_1, CONVERTED_TEMP_2 ];

You will have similar arrays for the Celsius and Kelvin portions of your program.

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

Implement the conditionals from the Part I bonus if you haven't already!

temperature_converter's People

Contributors

amaseda 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.