5.2 Switch Challenge
Hello everyone, as planned in the previous video . Let’s do a little switch challenge. So the challenge is to create a new switch statement using char instead of int. Create a new char variable. Create a switch declaration testing A,B,C,D or E. Then, display a message if any of these items is found, and then break. After adding a "default" that displays a message saying not found. So are you ready? Now we’re going to make the correction. I hope you managed to do that. We come here. For example, we write char charValue Is equal to 'A'. So a reminder, char is a unicode character, surrounded by simple dimensions. Then we write switch In parentheses, the variable "charValue". Then we write the box 'A' "A, has been found" We do the same for the 'B' box. So, "B, was found". break Then we make the box 'C', the box 'D', the box 'E' And so we do in parentheses. charValue + " was found". we take a break. And now we do a "default" If none of these alphabets were found. Then we take a break. Now we can test it So, as we can see. 'A', has been found. Now if change 'A' to 'B'. 'B', was also found . And if I write 'E', for example 'E', has been found. And if I write 'F' 'F', could not be found. Because she’s not in the box. If I write 'a' tiny. It’s not gonna work. Because we made a statement. 'A', upper case in the box. That was it for this little challenge. It was really easy. So I’ll see you at the next video.