Using Range In Switch Case

[Solved] Using Range In Switch Case | Matlab - Code Explorer | yomemimo.com
Question : switch/case with numeric range

Answered by : gbor-deutsch

function getCategory(age) { var category = ""; switch (true) { case isNaN(age): category = "not an age"; break; case (age >= 50): category = "Old"; break; case (age <= 20): category = "Baby"; break; default: category = "Young"; break; }; return category;
}
getCategory(5); // will return "Baby"

Source : https://stackoverflow.com/questions/20147879/switch-case-can-i-use-a-range-instead-of-a-one-number | Last Update : Tue, 15 Dec 20

Answers related to using range in switch case

Code Explorer Popular Question For Matlab