0

is this valid for JS vars

Trying to rewrite my currect Code Exercise 'CHECK YOUR ZODIAC' to use 'Switch' So I write 'Conditions' as variable, example below, var star1 = month['January'] && day <= 20 || month['February'] & day <= 19; var result = ""; switch(result) { case star1 = document.write("sample); break; My concern is : Is it valid to write Condition as variable? thank you.. I'm still learning đŸ€—

3rd May 2020, 5:41 AM
Ridzuan Wan
Ridzuan Wan - avatar
4 Answers
+ 4
No, it's still not how switch is used. switch is for discrete choices, for example: switch (day) : case 1 : case 2 : case 3 : .... case 10 : alert("early this month"); break; case 11 : case 12 : ....
3rd May 2020, 6:12 AM
Gordon
Gordon - avatar
+ 2
It's not how switch is used.
3rd May 2020, 5:42 AM
Gordon
Gordon - avatar
0
sorry the question is confusing.. I edited the question
3rd May 2020, 5:45 AM
Ridzuan Wan
Ridzuan Wan - avatar
0
Ok, Thanks Gordon 😁 I will study it again..
3rd May 2020, 6:16 AM
Ridzuan Wan
Ridzuan Wan - avatar