Advertisement
vborislavova

04. metricConverter -Conditional Statements - Exercise

Feb 22nd, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function metricConverter(input) {
  2.     let num = Number(input.shift());
  3.     let type1 = input.shift();
  4.     let type2 = input.shift();
  5.  
  6.     if (type1 == "mm") {
  7.         num /= 1000;
  8.     } else if (type1 == "cm"){
  9.         num /= 100;
  10.     }
  11.     if (type2 == "mm"){
  12.         num *= 1000;
  13.     } else if (type2 == "cm"){
  14.         num *= 100;
  15.     }
  16.     console.log(num.toFixed(3));
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement