在我的二十一点cli ruby​​中的错误消息

问题描述:

我正在学习一个learn.co实验室二十一点cli线是https://learn.co/tracks/web-development-fundamentals/intro-to-ruby/looping/blackjack-cli?batch_id=166&track_id=10415然而,需要通过的15个例子,我不断收到一个错误6我主要有麻烦initial_round方法和命中?方法。在我的二十一点cli ruby​​中的错误消息

i keep getting an error in the initial round method asking me to call on the display_card_total method to print the sum of cards and the hit? confuses me a little as to what exact its asking

def deal_card 
rand(11) + 1 
end 

def display_card_total(card) 
    puts "Your cards add up to #{card}" 
end 

def prompt_user 
    puts "Type 'h' to hit or 's' to stay" 
end 

def get_user_input 
    gets.chomp 
end 

def end_game(card_total) 
    puts "Sorry, you hit #{card_total}. Thanks for playing!" 
end 

def initial_round 
    deal_card 
    deal_card 
    return deal_card + deal_card 
    puts display_card_total 
end 

def hit? 
    prompt_user 
end 

def invalid_command 
    puts "Please enter a valid command" 
end 

希望这是足够的信息

您没有按照分配。

它指定hit?方法应该利用目前卡总的说法,所以它应该是...

def hit?(current_card_total) 

然后,它规定你应该做prompt_userget_user_input,然后测试结果为“h”或“s”或其他,并采取适当的措施。

如果你为命中做一个“h”,current_card_total将会增加,否则如果你做一个“s”它没有改变,但你需要返回值,不管它是否被改变。

如果用户输入其他旁边的“H”或“S”是你叫invalid_command方法和正确的值再次提示(prompt_user),你可以用get_user_input

再次尝试这样得到回应,这样的事情...

def hit?(current_card_value) 
    prompt_user 
    user_input = get_user_input 
    while user_input != "h" && user_input != "s" 
    invalid_command 
    prompt_user 
    user_input = get_user_input 
    end 
    if user_input == "h" 
    current_card_value += deal_card 
    end 
    return current_card_value 
end 

有几件事情错了你initial_deal只是下手,你需要跟踪deal_card结果的一个变量

current_card_total = deal_card 
current_card_total += deal_card 

那样current_card_total已累计。正在做

deal_card 
deal_Card 

不存储任何地方的结果deal_card

+0

这让我有如此多的感觉,我真的觉得好像有时我想我需要努力阅读错误消息的能力更多 – Daquon

+0

我仍然遇到初始问题 – Daquon