I'm trying to increase the interval speed as the levels go up
Post any code you think might be relevant (one fenced block per file)
// this is where I call the interval and as you can setting the interval didn't work in the function.
function changeChoice() {
console.log("this function ran")
// if(level < 3){
// interval = 3000
// }else if(level >= 3){
// interval = 2500
// console.log("it sped up")
// }
intervalID = setInterval(compareChoices,interval)
}
///so then I put it in the callback function
function compareChoices () {
console.log(`it's level ${level}\n`,
`player: ${playerTurn[0]} \n`,
`computer: ${computerTurn[0]} \n`,
computerTurn[0] === playerTurn[0])
if(playerTurn[0] === computerTurn [0]){
//clear out arrays
playerTurn = []
computerTurn = []
// add level
level += 1
if (level < 3){
interval = 3000
console.log(`interval is now:${interval} `)
}else if (level >= 3){
interval = 600
console.log(`interval is now:${interval}\n `,
changeChoice)
}
//set my new choice
randomChoice = getRandomChoice()
readOut.innerText = `...${randomChoice}`
computerTurn.push(randomChoice)
//chang etext color in case random choice is the same choice
if(level %2 !== 0){
readOut.style.color = "black"
}else{
readOut.style.color = "purple"
}
}else{
stopGame()
}
}
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
No error message and I can get it console log, and actually change the variable interval but the speed doesn't actually change
What is your best guess as to the source of the problem?
I am assuming that the function changeChoice is only actually running once and then relying on compareChoice but I couldn't get it to work when it was set on the actual function
What things have you already tried to solve the problem?
I tried using the if else statement in 3 different functions and the compare choices was the only one that actually ran but it didn't change the function interval
What's the problem you're trying to solve?
I'm trying to increase the interval speed as the levels go up
Post any code you think might be relevant (one fenced block per file)
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
No error message and I can get it console log, and actually change the variable interval but the speed doesn't actually change
What is your best guess as to the source of the problem?
I am assuming that the function changeChoice is only actually running once and then relying on compareChoice but I couldn't get it to work when it was set on the actual function
What things have you already tried to solve the problem?
I tried using the if else statement in 3 different functions and the compare choices was the only one that actually ran but it didn't change the function interval
Paste a link to your repository here[
https://github.com/skbarbee