- Joined
- Dec 1, 2022
- Messages
- 1
- Reaction score
- 1
Hi all!
I've used a switch case statement in a function that needs to determine the colour of a fruit. The issue is that I'm not sure how to get the outcome from the statement. Should I go for an if/else statement instead?
The code is as follows:
I'm unable to obtain the result, and I'm not sure if I require a'return' value or something similar.
Before running this code, I did some web research and read a handful of articles to better comprehend the concept; my sources of information were Wiki, scaler, and GFG.
Thanks in advance!
I've used a switch case statement in a function that needs to determine the colour of a fruit. The issue is that I'm not sure how to get the outcome from the statement. Should I go for an if/else statement instead?
The code is as follows:
Code:
function fruitColor(fruit) {
switch(color) {
case "apple" : green;
break;
case "banana" : yellow;
break;
case "kiwi" : green;
break;
case "plum" : red;
break;
}
}
var result = fruitColor(plum);
Before running this code, I did some web research and read a handful of articles to better comprehend the concept; my sources of information were Wiki, scaler, and GFG.
Thanks in advance!