This forum is now read-only. Please use our new forums! Go to forums
banner
Close banner
[resolved] 3/6 What is a default case?
<?php
$fruit = "Apple";
switch ($fruit) {
case 'Apple':
echo "Yummy.";
break;
}
?>
that is my code and the error says : Oops, try again. Make sure you add the default case!
but it returns Yummy.
also- im not really understanding what the default case really mean so if you could explain that it would be great.
Answer 52e08c269c4e9dbb7600163b
5 votes
You can put in a default case that will handle anything that didn’t match any of the specific cases that you coded for.
Here is an example of a switch with a default case:
switch (2) {
case 0:
echo 'The value is 0';
break;
case 1:
echo 'The value is 1';
break;
case 2:
echo 'The value is 2';
break;
default:
echo "The value isn't 0, 1 or 2";
}
Answer 52e10c259c4e9d1e0c00129d
0 votes
In the editor you have the code of the previous exercise. Make the code use the alternative syntax rather than the curly-brace syntax.
Answer 535197e08c1ccc82a8000782
Answer 535198de631fe99306000780
Answer 56025de19113cb121b0006eb
0 votes
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$fruit = "Apple";
switch ($fruit) {
case:
echo "Apple";
echo "Yummy.";
break;
default:
}
?>
</body>
</html>
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
2 comments
thanks, shoulda known as it was called DEFAULT CASE haha.
Glad I could help. When you look back in a few months it will all seem so much more sensible :)