Variables

Base

// Calculate the circumference of a circle given its radius
var pi = 3.14;
var radius = 21;
var circumference = 2 * pi * radius;

// Convert Celsius to Fahrenheit
var celsius = 33;
var fahrenheit = celsius * 1.8 + 32;

// Calculate the volume of a cube given a side length
var sideLength = 3;
var cubeVolume = sideLength ** 3;

// Calculate the gradient percentage of a road given rise and run
var rise = 50;
var run = 500;
var roadGradientPercentage = rise / run * 100;

// Convert millilitres to pints
var millilitres = 100;
var pints = millilitres / 473176.473;
Description

Write code to represent each of the following. Use descriptive variable names that explain what you are calculating. JavaScript convention is to write variables in camelCase.

  1. Calculate the circumference of a circle given its radius
  2. Convert Celsius to Fahrenheit
  3. Calculate the volume of a cube given a side length
  4. Calculate the gradient percentage of a road given rise and run
  5. Convert millilitres to pints