repl.it
@mcuringa/

Variable-Examples

ES6

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Example problems
 *********************************/

// 1. Ask the user for their name, and then 
// print "Hello, <name>" to the console, 
// where <name> is the string they entered.

let name = window.prompt("What's your name?");
console.log("Hello, " + name);


// 2. Ask the user how old they are. After they enter 
// the information, print out the year they were born.

// let age = window.prompt("How old are you?");
// let year = 2018;
// let born = year - age;

// console.log("You were born in " + born + " or " + (born - 1));



// 3. Calculate all of the powers of 2 from 2^2 to 2^8.
// console.log(2 ** 2);
// console.log(2 ** 3);
// console.log(2 ** 4);
// console.log(2 ** 5);
// console.log(2 ** 6);
// console.log(2 ** 7);
// console.log(2 ** 8);

// 4. You can calculate the volume of a cube by raising 
// the length of a side of a cube to the power of 3. 
// Ask the user for the length of one
// side of a cube and then print out the volume.

// let side = window.prompt("What is the length of one side of your cube?");
// let volume = side ** 3;
// console.log("The volume of a cube with side, " + side + " measures " + volume);

// 5. Your car gets 32 miles per gallon, on average. 
// How many gallons of gas would you use to 
// drive 412 miles?

// let mpg = 32;
// let miles = 412;
// let gallonsOfGas = miles / mpg;

// console.log("You need " + gallonsOfGas + " gallons of gas to drive " + miles + " miles.");
Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie
?