This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Control Flow: Switch Forum

View Course » View Exercise

0 points
4ebbbf38d8dafbe876a6446511eeac42?s=140&d=retro
Submitted by
Willis Wachira
about 4 years ago

switch

how do i convert a if else statement program -(that triggers one to enter the students marks then outputs the grade given a particular range e.g 80-100 is A, 70-80 is B....) to a switch statement. i have tried to use ranges as the cases but i doesn't work.


0 votes

permalink

You can use logical operators so your code would look something like this:

switch($grade){
case ($grade >= 70 && $grade <= 80): echo "B"; break;
case ($grade >= 80 && $grade <= 100): echo "A"; break;
default: echo "default"; break;
}

411 points
5271ef46548c35efbc002f14_26537942
Submitted by
macky
almost 4 years ago