Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch statements can help with long if/else #29

Open
oliverjam opened this issue Feb 11, 2022 · 0 comments
Open

Switch statements can help with long if/else #29

oliverjam opened this issue Feb 11, 2022 · 0 comments

Comments

@oliverjam
Copy link

if (month == "Dec") {
if (day < 22) astro_sign = "Sagittarius";
else astro_sign = "capricorn";
} else if (month == "Jan") {
if (day < 20) astro_sign = "Capricorn";
else astro_sign = "aquarius";
} else if (month == "Feb") {
if (day < 19) astro_sign = "Aquarius";
else astro_sign = "pisces";
} else if (month == "Mar") {

This might be a good use-case for a switch statement to reduce some of the if/else noise

switch (month) {
  case "Dec":
    astro_sign = day < 22 ?  "Sagittarius" : "capricorn"; 
    break;
  case "Jan":
    astro_sign = day < 20 ? "Capricorn" : "aquarius"; 
    break;
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant