Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ukhlivanov/6260480aaf89f48599f19b985e2eabf1 to your computer and use it in GitHub Desktop.
Save ukhlivanov/6260480aaf89f48599f19b985e2eabf1 to your computer and use it in GitHub Desktop.
ThinkFul(Numbers)
function computeArea(width, height) {
// your code here
return width*height;
}
/* 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 isDivisible(divisee, divisor) {
// your code here
if(divisee%divisor===0){
return true;
}
return false;
}
/* 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();
function celsToFahr(celsTemp) {
// your code here
return celsTemp*1.8+32;
}
function fahrToCels(fahrTemp) {
// your code here
return (fahrTemp-32)*1.8;
}
/* 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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment