mercredi 8 mars 2017

typescript classes, taking input from a prompt and if/else statement

i'm sorry, my code is a huge mess right now. what I am trying to figure out, is how can I take the input that I get from a prompt, store it in a variable, so that I can use it in an if/else statement?

I'm trying to make a quiz that prompts the user to enter the answer to a question, and then using the if/else statement to determine if the answer is write or not.

help?

//store score total
let pointsCount = 0;

//questions
class Question {
questionName: string;
questionString: string;
public questionSomething(someAnswer){
return someAnswer = prompt(`${this.questionString}`);

}
}

//not sure if this is needed yet
class Points {
  countPoint: number;
  addToPoints(newPoints){

  }
}


let question1 = new Question();
question1.questionString = "What is the California State Flower? 1. Rose. 2. Tulip. 3. Poppy";
question1.questionSomething(this.questionString);
let answerOne = question1.someAnswer;

storing question1.someAnswer into a variable at the end of the code isn't working, i'm thinking it has to do with someAnswer being defined inside the class function? if thats the case, what would be the better way to approach this rather than having it as a function or?

Aucun commentaire:

Enregistrer un commentaire