'How to repeat if statement multiple times in a while loop
I’m creating an bot that will play a card game in which you need to guess if the value of the next card is going be higher, lower or equal.
I want to always guess whether the first and second cards are going to be equal (which will give me 12 points). I have no problem doing that, but after that I want the bot to follow the safer way in guessing the cards. I also have the option to skip cards.
Here is my code and I will describe the issue I’m having:
while (currentMulti >= 12) {
if (lastCard == "K" || lastCard == "J" || lastCard == "Q" || lastCard == "10" || lastCard == "9") {
nextGuessLow(lastCard)
lastCard = nextGuessLow.lastCard
currentMulti = nextGuessLow.currentMulti
} else if (lastCard == "A" || lastCard == "2" || lastCard == "3" || lastCard == "4" || lastCard == "5") {
nextGuessHigh(lastCard)
lastCard = nextGuessHigh.lastCard
currentMulti = nextGuessHigh.currentMulti
} else {
nextGuessSkip(lastCard)
lastCard = nextGuessSkip.lastCard
currentMulti = nextGuessSkip.currentMulti
}
}
The problem is that the script/bot only guesses if the 3rd card is going to be lower or high one time, and after guessing the 3rd card it goes back to guessing the next cards (4th, 5th) and so on as equal. What can the issue be? If I need to add the rest of the code that includes the equal guess part then please let me know.
Solution 1:[1]
Ok i figured out what the problem was, actually an very rookie mistake by me lol, the lastCard and currentmulti values need to be returned with an await operator, i was trying to call it without the await which it was kinda glitching and not returning the value i needed
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user132741 |
