Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- function celsToFahr(celsTemp) {
- return celsTemp * 1.8 + 32;
- }
- function fahrToCels(fahrTemp) {
- 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() {
- var cel2FahrInput = 100;
- var cel2FahrExpect = 212;
- var fahr2CelInput = 32;
- var 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();
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">function celsToFahr(celsTemp) {
- return celsTemp * 1.8 + 32;
- }
- function fahrToCels(fahrTemp) {
- 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() {
- var cel2FahrInput = 100;
- var cel2FahrExpect = 212;
- var fahr2CelInput = 32;
- var 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();
- </script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement