将快速答案与阵列上的选项进行比较

时间:2015-11-05 01:25:25

标签: javascript arrays

我想要返回true或false。并且如果使用大写,则要确保接受答案。

// Seems like this delegate method gets called *before* the requestDidFinish method. Don't really want to rely on that behavior though.
public func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
    Assert.If(.ProductsRequest != self.requestDelegateUseType, thenPrintThisString: "Didn't have a product request")

    if 0 == response.invalidProductIdentifiers.count {

        /*
        #if DEBUG
            // Debugging-- simulate an error fetching products.
            self.fetchProductsCompletion!(products: nil, error: nil)
            return
        #endif
        */

        self.fetchProductsCompletion?(products: response.products, error: nil)
        //self.fetchProductsCompletion = nil
    }
    else {
        let message = "Some products were invalid: \(response.invalidProductIdentifiers)"
        self.fetchProductsCompletion!(products: nil, error: NSError.create(message))
    }
}

jsbin

1 个答案:

答案 0 :(得分:0)

您正在将用户输入的答案字符串转换为大写

var answer = question.toUpperCase();

但将其与预定义的小写套装进行比较:

var standardSuites = ['hearts', 'clubs', 'spades', 'diamonds'];

这当然不会受到打击。试试这个:

var answer = question.toLowerCase();