I am looking for a specific turtle race type of javascript tutorial to learn, similar to the one below. The issue with the one below is that it is python programming and I don’t feel ready to get my feet wet with another language at the moment. Any help would be much appreciated!
No problem, I decided to use what I know to try and build one anyway… however, I have encountered a problem.
While editing my code somehow I made a mistake that makes the 3 colors start at position 100 on the x axis as opposed to the position 10. If you can assist me in how to make it so when the user presses the watch race button, the colors start their race from 10 and change their pace when they reach a certain position on the x axis. The link is below.
Hi, that was a different issue. The one I replied you with is my current issue:
the 3 colors start at position 100 on the x axis as opposed to the position 10.
They are supposed to start racing and change speeds from certain marks like 100 on the x-axis, etc… but instead as you will notice, they end up starting from position 100 instead of 10
runnerRed = new component(20, 20, "red", 0, 50); i set x to 0
runnerBlue= new component(20, 20, "blue", 0, 120);
runnerGreen= new component(20, 20, "Green", 0, 200);
```
it will make the component start from x = 0 not x = 10
is that what you want or i miss understand something
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);
}
}