I want the components to start from x=10… however, I want their speeds to vary as they race and when I implemented the if stat… oh… I just figured it out oh my god… I got it! == instead of =… because… yeah… I got it… sorry for wasting your time… I been on this code for a while an I guess I needed to think out loud to anyone who would listen to figure it out… in my own head I couldn’t find the solution.
var speed= [2.7, 2.9,3, 2.1, 2.3 ,2.4 , 2.6,2, 2.2 , 2.5 , 2.8]
function runnersSpeed(){
var speedRan= speed[Math.floor(Math.random()*speed.length)];
return speedRan;
}
function race(){
runnerBlue.speedX +=runnersSpeed();
console.log("Blues first speed"+runnerBlue.speedX);
runnerGreen.speedX +=runnersSpeed();
console.log("Greens first speed"+runnerGreen.speedX);
runnerRed.speedX +=runnersSpeed();
console.log("Reds first speed"+runnerRed.speedX);
if(runnerBlue.x=100){
runnerBlue.speedX=0;
runnerBlue.speedX+=runnersSpeed();
console.log("Blue's second speed"+runnerBlue.speedX);
}
if(runnerRed.x=100){
runnerRed.speedX=0;
runnerRed.speedX+=runnersSpeed();
console.log("Reds second speed"+runnerRed.speedX);
}
if(runnerGreen.x=100){
runnerGreen.speedX=0;
runnerGreen.speedX+=runnersSpeed();
console.log("Green second speed"+runnerGreen.speedX);
}
}