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!
Agree with a comment or answer? Like () to up-vote the contribution!
I am confused by the IF/ElSE exercise. What exactly is being evaluated here?
I would expect IF/ELSE to be more along the lines of
Variable1 = 2
Variable2 = 3
If Variable1 > Variable2: do something
Else: do something different.
So what exactly are we evaluating to see whether or not it is true?
message <- "I change based on a condition."
if (TRUE) {
message <- "I execute this when true!"
} else {
message <- "I execute this when false!"
}
print(message)
I was stuck on this questions as well. I believe the difference is single quotes vs double quotes surrounding each message. (Double quotes give an error?)
I learn better when I understand the fundamentals of the evaluation. What is being evaluated as true or false in this situation?
It was easy to pass the lesson but it feels like I am only learning the R syntax and not the logic behind R. I hope this will go into more detail in later sections.
@text9311646494@danielsinclair030878@jmac32935
yes, the logic behind simply typing TRUE into an if statement (which takes an evaluation of a logical statement) isn’t fully explained here. But in other programing languages true always evaluates to being true, it will never print the else statement. hope this helps!
Single/double quotes did not matter to me, but changing the spacing so else is on the same line as the end curly braces and an extra empty line between the end curly brace and print statement passed it for me. Is R white-space sensitive or is this just Codecademy’s grading system being wonky for this exercise?
Hi! I ended the else line with }; as I usually do in SQL and I passed but I would say the space is more correct in R.
Answer:
message <- “I change based on a condition.”
if (TRUE) {
message <- “I execute this when true!”
} else {
message <- “I execute this when false!”
}
@davidgarcia719776693@text9311646494
Basically a logical / boolean is an unassigned variable that has an initialized value. In some languages it is initialized as FALSE and in some, like R, it is initialized as TRUE. To change the value you have to explicitly assign it to a variable container and state the value.
What an awful lesson!
How do they not give an example of something like this? lmao it’s almost comical.
They reference a condition in the parentheses and then just have a boolean T/F in the parentheses.
That is NOT a condition, that is the RESULT of a condition.
Glad I tried the free account before paying money for this garbage. I figured this lesson out by Googling and stumbling across a FREE site. So you obviously don’t always get what you pay for.
message ← “I change based on a condition.”
if (TRUE) {
message ← “I execute this when true!”
} else {
message ← “I execute this when false!”
}
print(message)
Shouln´t it just execute the else statement because it is defined as false?
message ← FALSE
if (TRUE) {
message ← “I execute this when true!”
} else {
message ← “I execute this when false!”
}
print(message)
You do not need to write a full program, only the IF / ELSE statement, it will be run by the system passing a TRUE and a FALSE value and validating the result.
Curly braces, on an US keyboard are on top of the square braces =, next to the P key and left of the RETURN key.