FAQs on the exercise _Switch Statement: Interval Matching _
There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
So, I’m confused as to why I have to input
villain = “Emperor Palapatine”
when I could just do
print (“Emperor Palapatine”). I don’t understand why we’d use the former and not the later. The later actually make the code work. The ‘villain =’ doesn’t make the code work but the ‘Next’ but is all excited and says continue?
I’m not sure if I should be asking this here but this is my code and I’m not getting any errors but nothing is printing just wondering if I did something wrong or if it is a bug.
var episode = 2
var villain: String
// Write your code below
switch episode {
case 1…3:
villain = “Emperor Palpatine”
case 4…6:
villain = “Darth Vader”
case 7…9:
villain = “Kylo Ren”
default:
villain = “”
@byteblitz hmm I think either the wording may be a little wack or the lesson meant to say that it has already created the two variables we need to use in the exercise…
@blogcoder83184 My take on this is that both ways work, however, if we run it using print (“Emperor Palapatine”), the code isn’t saved, whereas if we store the result as a variable (in this case, villain = “Emperor Palapatine”), we can always use it later, if needed, by calling the variable…
I had super fun with this lesson. I recognized the mistake I made yesterday and fixed it before I got an error and it worked out ok. I also enjoyed step four and playing around with it until I was able to feel more confident about the whole use of switches
Came here with exactly this question. The lesson definitely doesn’t distinguish exactly where print() goes but accepts its placement within the curly bracket as correct. Very confusing!