0
0
Ruby on Railsframework~10 mins

ERB template syntax in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to output the value of name in an ERB template.

Ruby on Rails
<p>Hello, <%= [1] %>!</p>
Drag options to blanks, or click blank then click option'
Aname
Bprint(name)
Cecho name
Dputs name
Attempts:
3 left
💡 Hint
Common Mistakes
Using Ruby methods like print or puts inside <%= %> which is unnecessary.
Forgetting to use <%= %> and using <% %> which does not output.
2fill in blank
medium

Complete the ERB code to run Ruby code without outputting anything.

Ruby on Rails
<% [1] %>
Drag options to blanks, or click blank then click option'
Aputs x
Bx
Cx = 5
Dprint x
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to output with <%= %> when you only want to run code.
Using methods like puts or print inside <% %> which won't show output.
3fill in blank
hard

Fix the error in this ERB code to correctly output the result of 2 + 3.

Ruby on Rails
<%= 2 + [1] %>
Drag options to blanks, or click blank then click option'
A2
B+
Cfive
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the plus sign again causing syntax errors.
Using a word like 'five' which is not a number.
4fill in blank
hard

Fill both blanks to create a loop in ERB that outputs numbers 1 to 3.

Ruby on Rails
<% (1..3).[1] do |num| %>
  <p><%= num [2] 0 %></p>
<% end %>
Drag options to blanks, or click blank then click option'
Aeach
B+
C%
Dtimes
Attempts:
3 left
💡 Hint
Common Mistakes
Using times on a range which is invalid.
Using % instead of + inside the output, causing division by zero.
5fill in blank
hard

Fill all three blanks to create a conditional in ERB that outputs 'Even' or 'Odd' for numbers 1 to 3.

Ruby on Rails
<% (1..3).each do |num| %>
  <% if num [1] 2 [2] 0 %>
    <p>Even</p>
  <% else %>
    <p>[3]</p>
  <% end %>
<% end %>
Drag options to blanks, or click blank then click option'
A%
B==
COdd
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of == causing logic errors.
Forgetting to output 'Odd' in the else block.