Complete the code to output the value of name in an ERB template.
<p>Hello, <%= [1] %>!</p><%= %> which is unnecessary.<%= %> and using <% %> which does not output.In ERB, <%= %> outputs the value of the Ruby expression inside. You just need the variable name name to display its value.
Complete the ERB code to run Ruby code without outputting anything.
<% [1] %><%= %> when you only want to run code.<% %> which won't show output.Use <% %> to run Ruby code without output. Assigning x = 5 inside is correct.
Fix the error in this ERB code to correctly output the result of 2 + 3.
<%= 2 + [1] %>
The expression 2 + 3 adds two numbers. You need to fill in 3 to complete it.
Fill both blanks to create a loop in ERB that outputs numbers 1 to 3.
<% (1..3).[1] do |num| %> <p><%= num [2] 0 %></p> <% end %>
times on a range which is invalid.% instead of + inside the output, causing division by zero.each loops over the range 1 to 3. Inside, num + 0 outputs the number itself (1, 2, 3).
Fill all three blanks to create a conditional in ERB that outputs 'Even' or 'Odd' for numbers 1 to 3.
<% (1..3).each do |num| %> <% if num [1] 2 [2] 0 %> <p>Even</p> <% else %> <p>[3]</p> <% end %> <% end %>
!= instead of == causing logic errors.The condition checks if num % 2 == 0 to find even numbers. If true, it outputs 'Even', else outputs 'Odd'.