The aim of this puzzle: Print out each letter, but change the T’s to U’s
Walkthrough of the solution: The for...of
loop will store each letter of 'GATTACA'
in element
. Before the element
is printed, we need to check if the letter is a 'T'
. If it is, then we should switch the letter to a 'U'
first. Inside the curly brackets of the If Statement, add element = 'U'
.
Sample code solution:
(Tap below to reveal)
var sequence = 'GATTACA';
for (var element of sequence) {
if (element === 'T') {
element = 'U';
}
print(element);
}
JavaScript Concepts: Code Block (if statement), Calling Functions, Identifiers, Loops, Conditionals (if statement), Variable Declaration
Grasshopper Concepts: print()
2 Likes
Man I’m doing it right but it is saying otherwise! WTHHH
1 Like
Could you post a screenshot of your code?
–Frankie
1 Like
Why do we use ===
in the if (element === ‘T’)
But only =
In element = ‘U’
?
===
checks if 2 things are equal
=
makes the variable on the left side equal to the right side
element === 'T'
– Check if the element
is currently equal to 'T'
element = 'U'
– Set the value of element
to 'U'
–Frankie
3 Likes
Try using a capital 'U'
instead of lowercase 'u'
.
–Frankie
Hey there,
The 1st time a variable is used, we declare it with the var
keyword. After it’s declared, however, we can just refer to it by its name. var
is used for new variables only.
Try changing var element = 'U'
to just element = 'U'
, and that should solve the problem.
Hope this helps!
Ben
1 Like