Here's the problem I'm working with:
The add_item method should take two arguments. The first argument is the item you want to add to the list and the second argument is the array (i.e. list) that the item will be added to. Don't add an item to the list if it already exists in the list.
Here is the code I have so far, and it keeps giving me an 'undefined local variable' error.
list = Array.new
list = [milk, eggs, oj, bacon]
def add_item(item, list)
if list.include?(item)
puts "item is already on list"
else list.push(item)
end
end
add_item(milk, list)
Aucun commentaire:
Enregistrer un commentaire