Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. function celsToFahr(celsTemp) {
  12. var fahr = (celsTemp *9)/5 +32;
  13. return fahr;
  14. }
  15.  
  16. function fahrToCels(fahrTemp) {
  17. var cels = (fahrTemp -32)*5/9;
  18. return cels;
  19. }
  20.  
  21.  
  22. /* From here down, you are not expected to
  23. understand.... for now :)
  24.  
  25.  
  26. Nothing to see here!
  27.  
  28. */
  29.  
  30.  
  31.  
  32. // tests
  33.  
  34. function testConversion(fn, input, expected) {
  35. if (fn(input) === expected) {
  36. console.log('SUCCESS: `' + fn.name + '` is working');
  37. return true;
  38. }
  39. else {
  40. console.log('FAILURE: `' + fn.name + '` is not working');
  41. return false;
  42. }
  43. }
  44.  
  45. function testConverters() {
  46. var cel2FahrInput = 100;
  47. var cel2FahrExpect = 212;
  48. var fahr2CelInput = 32;
  49. var fahr2CelExpect = 0;
  50.  
  51. if (testConversion(celsToFahr, cel2FahrInput, cel2FahrExpect) &&
  52. testConversion(fahrToCels, fahr2CelInput, fahr2CelExpect)) {
  53. console.log('SUCCESS: All tests passing');
  54. }
  55. else {
  56. console.log('FAILURE: Some tests are failing');
  57. }
  58. }
  59.  
  60. testConverters();
  61. </script>
  62.  
  63.  
  64.  
  65. <script id="jsbin-source-javascript" type="text/javascript">function celsToFahr(celsTemp) {
  66. var fahr = (celsTemp *9)/5 +32;
  67. return fahr;
  68. }
  69.  
  70. function fahrToCels(fahrTemp) {
  71. var cels = (fahrTemp -32)*5/9;
  72. return cels;
  73. }
  74.  
  75.  
  76. /* From here down, you are not expected to
  77. understand.... for now :)
  78.  
  79.  
  80. Nothing to see here!
  81.  
  82. */
  83.  
  84.  
  85.  
  86. // tests
  87.  
  88. function testConversion(fn, input, expected) {
  89. if (fn(input) === expected) {
  90. console.log('SUCCESS: `' + fn.name + '` is working');
  91. return true;
  92. }
  93. else {
  94. console.log('FAILURE: `' + fn.name + '` is not working');
  95. return false;
  96. }
  97. }
  98.  
  99. function testConverters() {
  100. var cel2FahrInput = 100;
  101. var cel2FahrExpect = 212;
  102. var fahr2CelInput = 32;
  103. var fahr2CelExpect = 0;
  104.  
  105. if (testConversion(celsToFahr, cel2FahrInput, cel2FahrExpect) &&
  106. testConversion(fahrToCels, fahr2CelInput, fahr2CelExpect)) {
  107. console.log('SUCCESS: All tests passing');
  108. }
  109. else {
  110. console.log('FAILURE: Some tests are failing');
  111. }
  112. }
  113.  
  114. testConverters();
  115. </script></body>
  116. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement