我有一个问题。我正在做一些测验,我需要你的帮助。我们需要显示不重复的随机问题。我不知道怎么做。我是 JavaScript 的初学者。下面是我的代码。
import { State } from "../../../framework/StateBase";
import { Conversation } from "../../../framework/ConversationBase";
import { getLanguage } from "../../../gateways/GigaaaGateway";
import { RatherGameGateway } from "../gateway/RatherGameGateway";
export class GetUserQuestionState extends State {
constructor(conversation: Conversation, name: string) {
super(conversation, name);
}
public configure(convo: any, bot: any) {
convo.beforeThread(this.name, async convo => {
let gateway = new RatherGameGateway();
let age = this.conversation.payload.userAges;
let ageCategory: number;
try {
let lang = await getLanguage(this.conversation.languageId, bot);
if (age > 11) {
ageCategory = 0;
let result = await gateway.findLangCodeAndAge(lang.code, ageCategory);
if (this.conversation.payload.counter === 0) {
this.conversation.payload.params.question = result[0].questions[Math.floor(Math.random())];
} else if (this.conversation.payload.counter > 0) {
this.conversation.payload.params.next_question = result[0].questions[this.conversation.payload.counter];
}
this.conversation.payload.counter++;
});
}
}
看看if循环。非常感谢!
胡子哥哥
月关宝盒
相关分类