jeudi 21 mars 2019

How to create if statement between two values?

I'm not sure what is going on here. Why "Part B" is never executed at this example? How to check between two numbers? I've looked over online e.g. this link, but i'm unsure what is going on.

var timeCounter;
var numberOfFrames;

function setup() {
   frameRate(5);
   timeCounter = 0;
   numberOfFrames = 10;
}

function draw() {

  
  timeCounter++; //Increase Timer by 1 - called in draw() function

  //Halfway through the animation
  if(timeCounter < numberOfFrames/2) { 
      console.log("part A = " + timeCounter);
  } 
  //between middle and end of the animation
  else if(timeCounter > numberOfFrames/2){

      console.log("part B = " + timeCounter);
  }
  //at the end of the animation
  else if(timeCounter < numberOfFrames){
      console.log("Repeat FRT = " + timeCounter);
      timeCounter = 0; //Reset timer
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.js"></script>

Aucun commentaire:

Enregistrer un commentaire