I have very little experience with JavaScript and am trying to write some code for an interaction I am developing.
What am I doing wrong???
// JavaScript Document for Tic-tac-toe check for 3 in a row
//Code for Customer Retention returns wrong as wrong answer
//Code Checking for 3 correct in a row
/*
This code is for a tic-tac-toe interaction. The changing of object states is controled within Captivate. This script follows the actions of Assigning the the variable true or false changing the state of the object (box in the tic tac toe game) and jumping back to the game slide. This script is then run in that same action. The “ShowFeedback” is an object with states that reveal a connection line stating they won
*/
if(window.A1Answer==true, window.B1Answer==true, window.C1Answer==true) {
cp.changeState(“ShowFeedback”,”A1_B1_C1″);
}
if else(window.A2Answer==true, window.B2Answer==true, window.C2Answer==true) {
cp.changeState(“ShowFeedback”,”A2_B2_C2″);
}
if else(window.A3Answer==true, window.B3Answer==true, window.C3Answer==true) {
cp.changeState(“ShowFeedback”,”A3_B3_C3″);
}
if else(window.A1Answer==true, window.A2Answer==true, window.A3Answer==true) {
cp.changeState(“ShowFeedback”,”A1_A2_A3″);
}
if else(window.B1Answer==true, window.B2Answer==true, window.B3Answer==true) {
cp.changeState(“ShowFeedback”,”B1_B2_B3″);
}
if else(window.C1Answer==true, window.C2Answer==true, window.C3Answer==true) {
cp.changeState(“ShowFeedback”,”C1_C2_C3″);
}
if else(window.A1Answer==true, window.B2Answer==true, window.C3Answer==true) {
cp.changeState(“ShowFeedback”,”A1_B2_C3″);
}
//Code Checking for 3 wrong in a row
if(window.A1Answer==false, window.B1Answer==false, window.C1Answer==false) {
cp.changeState(“ShowFeedback”,”A1_B1_C1″);
}
if else(window.A2Answer==false, window.B2Answer==false, window.C2Answer==false) {
cp.changeState(“ShowFeedback”,”A2_B2_C2″);
}
if else(window.A3Answer==false, window.B3Answer==false, window.C3Answer==false) {
cp.changeState(“ShowFeedback”,”A3_B3_C3″);
}
if else(window.A1Answer==false, window.A2Answer==false, window.A3Answer==false) {
cp.changeState(“ShowFeedback”,”A1_A2_A3″);
}
if else(window.B1Answer==false, window.B2Answer==false, window.B3Answer==false) {
cp.changeState(“ShowFeedback”,”B1_B2_B3″);
}
if else(window.C1Answer==false, window.C2Answer==false, window.C3Answer==false) {
cp.changeState(“ShowFeedback”,”C1_C2_C3″);
}
if else(window.A1Answer==false, window.B2Answer==false, window.C3Answer==false) {
cp.changeState(“ShowFeedback”,”A1_B2_C3″);
}
if else(window.A3Answer==false, window.B2Answer==false, window.C1Answer==false) {
cp.changeState(“ShowFeedback”,”A3_B2_C1″);
}
//Code Checking for draw game
if else((window.A1Answer && window.B1Answer && window.C1Answer && window.A2Answer && window.B2Answer && window.C2Answer && window.A3Answer && window.B3Answer && window.C3Answer)==false||true) {
cp.changeState(“ShowFeedback”,”draw”);
}
Not really 100% sure what is happening with the interaction but here are a couple thoughts. This would be for the Captivate provided Script Window.
In the code when you check for if an answer is false – you might try putting quotes around that. For what it is worth – I prefer using the numbers 0 and 1 as flags.
if (window.A3Answer==”false”) {
perform some action;
}
You also have the statements as if else rather than else if.
You may also try the following syntax…Instead of
if else(window.A1Answer==false, window.A2Answer==false, window.A3Answer==false)
else if ((window.A1Answer==”false”) && (window.A2Answer==”false”) && (A3Answer==”false”)) {
perform some action;
}
Also, I don’t know if you are using the above scripting comments in your script window but Captivate does not like those. Take them out. I don’t use external JS files so I cannot speak as to whether or not they are OK in that context but you’ll need to remove them for the internal window.
I have worked up a sample tic-tac-toe game that I will share in another post. Perhaps it will yield some more insight as well.
You must be logged in to post a comment.