Created
October 18, 2017 19:07
-
-
Save goldtreefrog/b91d5494a1056ad04b34f58372658bd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function computeArea(width, height) { | |
return width * height; | |
} | |
let n1 = prompt("First number?"); | |
let n2 = prompt("Second number?"); | |
console.log("Area is " + computeArea(n1,n2)); | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
*/ | |
// tests | |
function testComputeArea() { | |
let width = 3; | |
let height = 4; | |
let expected = 12; | |
if (computeArea(width, height) === expected) { | |
console.log('SUCCESS: `computeArea` is working'); | |
} | |
else { | |
console.log('FAILURE: `computeArea` is not working'); | |
} | |
} | |
testComputeArea(); | |
//*********************************************************** | |
function celsToFahr(celsTemp) { | |
// [°F] = [°C] × 9⁄5 + 32 | |
return celsTemp * (9/5) + 32; | |
} | |
function fahrToCels(fahrTemp) { | |
return (fahrTemp - 32) * 5/9 | |
} | |
console.log(`If Celsius is ${n1}, then Farhenheit is ` + celsToFahr(n1)); | |
console.log(`If Farhenheit is ${n2}, then Celsius is ` + fahrToCels(n2)); | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
*/ | |
// tests | |
function testConversion(fn, input, expected) { | |
if (fn(input) === expected) { | |
console.log('SUCCESS: `' + fn.name + '` is working'); | |
return true; | |
} | |
else { | |
console.log('FAILURE: `' + fn.name + '` is not working'); | |
return false; | |
} | |
} | |
function testConverters() { | |
let cel2FahrInput = 100; | |
let cel2FahrExpect = 212; | |
let fahr2CelInput = 32; | |
let fahr2CelExpect = 0; | |
if (testConversion(celsToFahr, cel2FahrInput, cel2FahrExpect) && | |
testConversion(fahrToCels, fahr2CelInput, fahr2CelExpect)) { | |
console.log('SUCCESS: All tests passing'); | |
} | |
else { | |
console.log('FAILURE: Some tests are failing'); | |
} | |
} | |
testConverters(); | |
//*********************************************************** | |
function isDivisible(dividend, divisor) { | |
return (dividend % divisor) === 0; | |
}; | |
console.log(isDivisible(n1,n2)); | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! | |
*/ | |
// tests | |
function testIsDivisible() { | |
if (isDivisible(10, 2) && !isDivisible(11, 2)) { | |
console.log('SUCCESS: `isDivisible` is working'); | |
} | |
else { | |
console.log('FAILURE: `isDivisible` is not working'); | |
} | |
} | |
testIsDivisible(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment