Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. function celsToFahr(celsTemp) {
  2. return celsTemp * 1.8 + 32;
  3. // your code here
  4. }
  5.  
  6. function fahrToCels(fahrTemp) {
  7. return (fahrTemp - 32) / 1.8;
  8. // your code here
  9. }
  10.  
  11. /* From here down, you are not expected to
  12. understand.... for now :)
  13.  
  14.  
  15. Nothing to see here!
  16.  
  17. */
  18.  
  19. // tests
  20.  
  21. function testConversion(fn, input, expected) {
  22. if (fn(input) === expected) {
  23. console.log('SUCCESS: `' + fn.name + '` is working');
  24. return true;
  25. } else {
  26. console.log('FAILURE: `' + fn.name + '` is not working');
  27. return false;
  28. }
  29. }
  30.  
  31. function testConverters() {
  32. let cel2FahrInput = 100;
  33. let cel2FahrExpect = 212;
  34. let fahr2CelInput = 32;
  35. let fahr2CelExpect = 0;
  36.  
  37. if (
  38. testConversion(celsToFahr, cel2FahrInput, cel2FahrExpect) &&
  39. testConversion(fahrToCels, fahr2CelInput, fahr2CelExpect)
  40. ) {
  41. console.log('SUCCESS: All tests passing');
  42. } else {
  43. console.log('FAILURE: Some tests are failing');
  44. }
  45. }
  46.  
  47. testConverters();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement