Testing initial code in this lesson, seems wrong...?


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>


<Below this line, add a link to the EXACT exercise that you are stuck at.>

https://www.codecademy.com/en/courses/learn-ruby/lessons/a-night-at-the-movies/exercises/what-youll-be-building-5?action=lesson_resume&link_content_target=interstitial_undefined

<In what way does your code behave incorrectly? Include ALL error messages.>

I was testing this and decided to try to update the rating for a movie. The rating system is supposed to be values 0 through 4. I attempted to update “memento” with a value of 5 and it allowed me to do so without any errors. Shouldn’t the code be written to limit the values? I am new to coding but this seems like bad code if it allows values outside of specified ranges…

```

Replace this line with your code.

<do not remove the three backticks above>

#2

Ideally Yes, In this example it is entirely arbitrary, You asked the user for a number between 1 and 4. You’re just hoping that they will do so. In programming it is important to validate user input. You can use a loop or any number of tools to make sure they input a number between one and four.
Something simple like

while (choice >= 1 && choice <= 4) 
  code here

would suffice


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.