rabell17
rabell17

Reputation: 19

How do I correctly implement this switch statement?

I'm new to Javascript and I cannot get my switch statement to work correctly with each function or my default. Every thing I have tried fixes one issue but creates another. How do I correctly use my switch statement to get the correct return for my cases.

const f_to_c = (f = 32) => {
  total = 5 / 9 * (f - 32)
  result = (f + 'F = ' + total + 'C')
  return result;
}
console.log(f_to_c());

const c_to_f = (y = 0) => {
  total = 9 / 5 * (y) + 32
  results = (y + 'C = ' + total + 'F')
  return results;
}
console.log(c_to_f())

const convertTemp = (x = 'str', int = 0) => {

  switch ('f', 'c') {
    case 'c':
      return c_to_f(int);
    case 'f':
      return f_to_c(int);
    default:
      return ('Not an accurate temperature degree type..')
  }
};
console.log(convertTemp())

Upvotes: 0

Views: 33

Answers (1)

Evgeny Klimenchenko
Evgeny Klimenchenko

Reputation: 1194

You need to read a bit more how to create switch statement, here is good source

const convertTemp = (x = 'c', int = 0) => {  
    switch(x){
        case 'c':
             return c_to_f(int);
        case 'f':
            return f_to_c(int); 
        default:
            return ('Not an accurate temperature degree type..')
    }
};

Upvotes: 2

Related Questions