Quote (OnlyInMemories @ Oct 18 2016 01:40pm)
They are called logical part of program for a reason. You need think logically, understand and follow your code.
Sometimes when I get some errors in loops I make random printf statement inside them just to see how long have my code has passed and where it got broken.
In your case I think it is window.alert("sometext"); or something in JS, just insert couple of it in loops to see where it crashes.
Or you can post the problem here, and we go can trought it together, and I could try explain logic how I noticed it.
Even so, I have never did anything big in JS, so if it is some syntax error, someone will notice it faster than me :)
What i fixed was:
- added a break; statement to one of the cases because it was missing-in the var answer function i changed the second var answer to "answerq' because var answer was redefining var answer = function().. thus adding a 'q' to each case- deleted an extra }; at the very end of the code-in the mousePressed function, I defined var questionCount; because the questionCount's were not being stored anywhere (im kind of skeptical on this one)-added a few semicolons to where they were missing-added '===' to one of the else/if statements. Before it was only '==' which is not 'equal to'Code
//ProgramCodeGoesHere
var q = "Do you like the outdoors?";
var q1 = "Do you like to run?";
var q2 = "Do you like cheese?";
var q3 = "Do you like to swim?";
var yesButton = function () {
fill(255,255,255);
rect(40, 127, 50, 30);
fill(0,0,0);
textSize(18);
text("YES", 50,150);
};
var noButton = function(){
fill(255,255,255);
rect(290, 127, 50, 30);
fill(0,0,0);
textSize(18);
text("NO", 300, 150);
};
var question = function(){
fill(0,0,0);
textSize(18);
text(q, 100, 75, 300, 150);
};
var answer = function (a){
fill(255, 0, 0);
textSize(18);
var answerq = "";
switch (a) {
case 1:
answerq = "You are a horse!";
break;
case 2:
answerq = "You are a turtle!";
break;
case 3:
answerq = "You are a mouse!";
break;
case 4:
answerq = "You are a fish!";
break;
case 5:
answerq = "You are a cat!";
break;
}
text(answer, 150, 200);
noLoop();
};
draw = function (){
background(255,255,255);
fill(255,0,0);
textSize(24);
text("What animal are you?", 100, 30);
question();
yesButton();
noButton();
};
mousePressed = function(){
var questionCount;
if(mouseX >=40 && mouseX <= 90 && mouseY >= 127 && mouseY <= 157){ //yes
if (questionCount === 0 ){
q = q1;
questionCount = 1;
}
else if(questionCount === 1){
answer (0);
}
else if (questionCount === 2){
answer(3);
}
else if (questionCount === 2){
answer(4);
}
}
else if (mouseX >= 290 && mouseX <= 340 && mouseY >= 127 && mouseY <= 157){//no
if (questionCount === 0){
questionCount = 2;
q = q2;
}
else if (questionCount === 1){
answer();
}
else if (questionCount === 1){
q = q3;
questionCount = 3;
}
}
else if (questionCount === 3){
answer(4);
}
};
This post was edited by Shakti on Oct 18 2016 07:06pm