Can you find the error, please, and tell me how to fix it | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can you find the error, please, and tell me how to fix it

https://code.sololearn.com/c2c4GTBjide5/?ref=app

6th May 2023, 8:04 AM
Welcome To Dodgeball
Welcome To Dodgeball - avatar
2 Answers
+ 3
Define variable answer out of switch. https://www.sololearn.com/compiler-playground/cACVsrdDTDTk
6th May 2023, 8:25 AM
Black Winter
+ 1
If you must define and use a variable in `switch` labels, then wrap the label body inside curly brackets. However, in your case, it would be simpler to define variable <result> once before the `switch` and then just use it inside the labels. switch( math ) { case '+': { // code here ... } }
6th May 2023, 9:39 PM
Ipang