mardi 24 novembre 2015

Writing elegant JavaScript instead of if-then branches

How can I make the following code more elegant and readable?

if (this.flag === 1) {
  this.value -= 0.1;
}
if (this.value <= 0) {
  this.flag = 0;
}

if (this.flag === 0) {
  this.value += 0.1;
}
if (this.value >= 1) {
  this.flag = 1;
}

Aucun commentaire:

Enregistrer un commentaire