简体   繁体   English

未解决的参考:计数错误(Kotlin 函数)

[英]Unresolved reference: count error (Kotlin Function)

I am newly learning kotlin, and I am playing in the Playground that kotlin created.我正在学习 kotlin,我正在 kotlin 创建的 Playground 中玩耍。 As I was following the demo practice, I got these errors.在我进行演示练习时,我遇到了这些错误。 "Unresolved reference: count" "Unresolved reference: count" “未解决的引用:计数” “未解决的引用:计数”
I don't understand why because I exactly mimicked the demo that is in the Example on the website.我不明白为什么,因为我完全模仿了网站上示例中的演示。

fun generateAnswerMachine(countThreshold: Int): String {
val answerMachine = if (count < countThreshold) {
    "I have the answer."
} else {
    "The andswer eludes me"
}

return answerMachine 
}

val answerString = generateAnswerMachine(42)

Also,还,

fun generateAnswerString(countThreshold: Int): String = if (count > countThreshold) {
    "I have the answer"
} else {
    "The answer eludes me"
}

You gotta define count before using it in your function, like var count =...在 function 中使用它之前,您必须定义count ,例如var count =...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM