How to return undefined in switch statement without using if, case or switch

How to return undefined in switch statement without using if, case or switch
0

#1

Tell us what’s happening:
I cannot make the function to return undefined without using case, if or switch statement. your help will be appreciated.

Your code so far


// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  switch(val) {
    case "alpha": 
      result = "Adams";
      break;
    case "bravo": 
      result = "Boston";
      break;
    case "charlie": 
      result = "Chicago";
      break;
    case "delta": 
      result = "Denver";
      break;
    case "echo": 
      result = "Easy";
      break;
    case "foxtrot": 
      result = "Frank";
      break;
    default:
    result = '';
    break;

  }

  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup("undefined");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/using-objects-for-lookups


#2

I am not completely clear on what you mean by the question. But, you are passing a string undefined (“undefined”), rather than undefined variable. Drop the double quotes if you intend to pass an undefined javascript variable.


#3

not sure what you mean here:

  • if you actually want to return undefined, then just return undefined or don’t return anything.
  • if you’re trying to do the task, then that doesn’t have anything to do with it and you’ve misunderstanding something.