Lesson 1.3 Case When problems


#1

I can't seem to get past this test. It seems my code is fine and it returns the correct answer, but the it always giving me a message that my case statement doesn't puts "XXX" despite I matched the the output results correctly.

movies = {
    Matrix: 4.5,
    The_Godfather: 5,
    Jack_n_Jill: 0.5,
    Godzilla: 2
}

puts "type add to add a movie"
puts "type update to update a movie"
puts "type display to display movies"
puts "type delete to delete a movie"
print "your choice : "; choice = gets.chomp

case choice
when "add"
    puts "Added!"
when "update"
    puts "Updated!"
when "display"
    puts "Movies!"
when "delete"
    puts "Deleted!"
else
    puts "Error!"
end

So maybe anybody knows what seems wrong in this?

Thx


#2

If you change the 'print' command on line 12 of your code to 'puts', it will work.

Your code isn't wrong though. I'd guess, that the Codecademy test, that tests whether your code is correct, is confused, when there is no line break before the input in the console.

movies = {
    Matrix: 4.5,
    The_Godfather: 5,
    Jack_n_Jill: 0.5,
    Godzilla: 2
}

puts "type add to add a movie"
puts "type update to update a movie"
puts "type display to display movies"
puts "type delete to delete a movie"
puts "your choice: "; choice = gets.chomp

case choice
    when 'add'
        puts "Added!"
    when 'update'
        puts "Updated!"
    when 'display'
        puts "Movies!"
    when 'delete'
        puts "Deleted!"
    else
        puts "Error!"
end

#3

Hi Stefan, thanks a bunch. It worked! I guess it's just the way codeacademy engine checks the code.


#4

Lol, I had the same problem. So I just changed my "print" to "puts" and the answer was accepted. Hahaha. Omg. :wink:


#5
movies = {
    "The pick of destiny" => 5
}

puts "What is your favorite movie?"
choice = gets.chomp

case choice
when "add"
    puts "Added!"
when "update"
    puts "Updated!"
when "display"
    puts "Moevies!"
when "delete"
    puts "Deleted!"
else
    puts "Error!"
end

this is my code :slightly_smiling:


#6

sorry correction on the first puts: "What do you want to do: add, update, display of delete?"


#7

Hi, this is my code:
films = Hash.new
films = { Deathnote: 10,
}
puts "Pour ajouter à la liste : ajouter"
puts "Pour supprimer de la liste : supprimer"
puts "Pour modifier la liste : modifier"
puts "Pour afficher la liste : afficher"
puts "Votre choix :" ; choix = (gets.chomp)

case choix
when "ajouter"
puts "Ajouté!"
when "modifier"
puts "Mis à jour!"
when "afficher"
puts "Films!"
when "supprimer"
puts "Supprimé!"
else
puts "Erreur!"
end

I tried your solutions. It says that the program does not display "Deleted!" and the others but it actually does so I'm really confused..


#8

okay never mind I just didnt put a space before the exclamation points.......................;