[Solved] How do I make an if statement for 3 variables?


What you might want to do is separate this out to a different function, your functions should have namespaces to architect your application. You can do this with a helper lib found here.

You could try refactor code to something a little more structured like so:

module-controller.js

dali.util.namespace('myCompany.myApp.module');

myCompany.myApp.module.ClassName = function(maxGuesses) {
  this.maxGuesses = maxGuesses;
  this.numberOfGuesses = 0;
  this.alertMessage="Sorry, you have run out of guesses!";
};

myCompany.myApp.module.ClassName.prototype.hasMoreGuessesLeft = function() {
  return this.numberOfGuesses < maxGuesses;
};

myCompany.myApp.module.ClassName.prototype.guess = function(guess) {
  this.numberOfGuesses++;

  if(this.hasMoreGuessesLeft()) {
    //do something with the guess?
    console.log(guess);
  } else {
    window.alert(this.alertMessage + ' - ' + this.maxGuesses + ' max.');
  }
};

use it (import module-controller.js):

var maximum_guesses1 = 10;
var instance = new myCompany.myApp.module.ClassName(maximum_guesses1);
var guessAmount = 50;
for (int i = 0; i < guessAmount; i++) {
  instance.guess('Ive guessed ' + i + ' time(s)');
}

You can then pass in maximum_guesses1, maximum_guesses2, maximum_guesses3 accordingly.

I hope this helps.

Rhys

9

solved How do I make an if statement for 3 variables?