Not able to get the right answer

Hello,

Ive created a maths game called ‘Fishy Fractions’ where a fisherman has to catch a fish (with the correct answer in order to proceed to another round. How to play the game? There will be simple fraction questions (addition & subtraction). The user have to click on the right answer which is on the fish.

The problem Im facing: Whenever I click on the right answer, it return as if its a wrong answer. Sometimes it works, sometimes it does not. Im not sure where it went wrong.

But i think it got to do with the codes here.

Thanks!!

fishy = game.add.group();

            for(var i = 0;i < 10;i++)
            {
                game.colorPicker();
                var randomVelo = game.rnd.integerInRange(5,25);
                var randomIndex = game.rnd.integerInRange(120,500);
                var theX = game.rnd.integerInRange(-300,-120);
                var theY = randomIndex;
                var off = game.rnd.integerInRange(500,1200);
                posY[i] = theY + 100;
                if(level == 1)
                {
                    var randomNo = game.rnd.integerInRange(0,answerTop1.length-1);
                }
                if(level == 2)
                {
                    var randomNo = game.rnd.integerInRange(0,answerTop2.length-1);
                }
                if(level == 3)
                {
                    var randomNo = game.rnd.integerInRange(0,answerTop3.length-1);
                }
                if(level == 4)
                {
                    var randomNo = game.rnd.integerInRange(0,answerTop4.length-1);
                }

                else
                {
                    velo[i] = randomVelo / 10;
                    offset[i] = off;
                    fishes[i] = game.add.button(theX, theY,'fish2',game.next);
                    fishes[i].input.useHandCursor = false;
                    fishes[i].inputEnabled = true;
                    if(level == 1)
                    {
                        fishes[i].num = answerTop1.splice(randomNo,1);
                        fishes[i].denom = answerBot1.splice(randomNo,1);
                    }
                    else if(level == 2)
                    {
                        fishes[i].num = answerTop2.splice(randomNo,1);
                        fishes[i].denom = answerBot2.splice(randomNo,1);
                    }
                    else if(level == 3)
                    {
                        fishes[i].num = answerTop3.splice(randomNo,1);
                        fishes[i].denom = answerBot3.splice(randomNo,1);
                    }
                    else if(level == 4)
                    {
                        fishes[i].num = answerTop4.splice(randomNo,1);
                        fishes[i].denom = answerBot4.splice(randomNo,1);
                    }
                    fishes[i].animations.add('move',[0,1,2,3],5,true);
                    fishes[i].animations.play('move');


                    if(fishes[i].num < 10)
                    var textTop = game.add.text(60,30,fishes[i].num,style2);
                    else if(fishes[i].num > 9)
                    var textTop = game.add.text(55,30,fishes[i].num,style2);
                    if(fishes[i].denom > 9 && fishes[i].num <10)
                    var textBot = game.add.text(55,50,fishes[i].denom,style2);
                    else if(fishes[i].denom > 9 && fishes[i].num > 9)
                    var textBot = game.add.text(55,50,fishes[i].denom,style2);
                    else if(fishes[i].denom < 10)
                    var textBot = game.add.text(60,50,fishes[i].denom,style2);
                    var dash = game.add.sprite(55,53,'dash2');


                    textTop.stroke = "#000000";
                    textTop.strokeThickness = 5;
                    textBot.stroke = "#000000";
                    textBot.strokeThickness = 5;
                    fishes[i].addChild(textTop);
                    fishes[i].addChild(textBot);
                    fishes[i].addChild(dash);
                    textUp[i] = textTop;
                    textDown[i] = textBot;
                }
            }
        for(var i = 0;i<fishes.length;i++)
        {
            fishy.add(fishes[i]);
        }

        minus = game.add.sprite(30,-50,'minus');
        dash1.addChild(minus);
        minus.visible = false;

        plus = game.add.sprite(30,-50,'plus');
        dash1.addChild(plus);
        plus.visible = false;

        if(level == 1 || level == 2)
        {
            plus.visible = true;
            minus.visible = false;
        }
        else if(level == 3 || level == 4)
        {
            minus.visible = true;
            plus.visible = false;
        }

        dash1.scale.setTo(0.7);
        dash2.scale.setTo(0.7);


    },



    turnFish: function(fish)
    {
        switch(fish)
        {
            case 0:
            posY[fish] *= -1;
            timers[0] = game.time.now + game.rnd.integerInRange(500,1200);
            break;
            case 1:
            posY[fish] *= -1;
            timers[1] = game.time.now + game.rnd.integerInRange(500,1200);
            break;
            case 2:
            posY[fish] *= -1;
            timers[2] = game.time.now + game.rnd.integerInRange(500,1200);
            break;
            case 3:
            posY[fish] *= -1;
            timers[3] = game.time.now + game.rnd.integerInRange(500,1200);
            break;
            case 4:
            posY[fish] *= -1;
            timers[4] = game.time.now + game.rnd.integerInRange(500,1200);
            break;
            case 5:
            posY[fish] *= -1;
            timers[5] = game.time.now + game.rnd.integerInRange(500,1200);
            break;
        }
    }

    goTo2:function()
    {
        fishesx = [0,0,0,120,120,120,240,240,240,360,360,360,480,480,480,600,600,600];
        fishesy = [270,350,430,270,350,190,320,240,160,290,210,130,310,230,150,280,200,120];
        level = 2;
        part = 1;
        answerCounter = 1;
        reverseCounter = 0;
        fishes=[];
        goBack = false;
        this.game.state.start('Preloader');
    },
    goTo4:function()
    {
        fishesx = [0,0,0,120,120,120,240,240,240,360,360,360,480,480,480,600,600,600];
        fishesy = [270,350,430,270,350,190,320,240,160,290,210,130,310,230,150,280,200,120];
        level = 4;
        part = 1;
        answerCounter = 1;
        reverseCounter = 0;
        fishes=[];
        goBack = false;
        this.game.state.start('Preloader');
    },

    playAgain: function()
    {
        part = 1;
        level = 1;
        answerCounter = 1;
        fishes = [];
        reverseCounter = 0;
        goBack = false;
        fishesx = [0,0,0,120,120,120,240,240,240,360,360,360,480,480,480,600,600,600];
        fishesy = [270,350,430,270,350,190,320,240,160,290,210,130,310,230,150,280,200,120];
        answerTop1 = [3,4,5,4,3,3,3,4,3,6];
    answerBot1 = [6,12,8,9,4,10,8,6,12,10];
    answerTop2 = [5,11,7,8,4,2,7,7,5,9];
    answerBot2 = [6,12,8,9,5,3,9,10,6,10];
    answerTop3 = [1,1,3,1,1,1,2,4,2,1];
    answerBot3 = [6,6,8,10,4,8,6,10,9,12];
    answerTop4 = [3,8,1,5,3,3,3,8,1,1];
    answerBot4 = [6,12,8,10,6,8,10,15,9,12];
        values = [];
        this.game.state.start('StartScreen');
    },



        if(level == 1 || level == 2)
        {
            if(parseInt(denom2) > parseInt(denom1))
            {
                multiplier = parseInt(denom2)/parseInt(denom1);
                newNum = parseInt(num1)* multiplier;
                newDenom = parseInt(denom1) * multiplier;
                question = (parseInt(newNum) + parseInt(num2)) / newDenom;
            }
            else if(parseInt(denom2) < parseInt(denom1))
            {
                multiplier = parseInt(denom1)/parseInt(denom2);
                newNum = num2 * multiplier;
                newDenom = parseInt(denom2) * multiplier;
                question = (parseInt(newNum) + parseInt(num1)) / newDenom;
            }
        }
        else if(level == 3 || level == 4)
        {
            if(parseInt(denom2) > parseInt(denom1))
            {
                multiplier = parseInt(denom2)/parseInt(denom1);
                newNum = parseInt(num1)* multiplier;
                newDenom = parseInt(denom1) * multiplier;
                question = (parseInt(newNum) - parseInt(num2)) / newDenom;
            }
            else if(parseInt(denom2) < parseInt(denom1))
            {
                multiplier = parseInt(denom1)/parseInt(denom2);
                newNum = num2 * multiplier;
                newDenom = parseInt(denom2) * multiplier;
                question = (parseInt(newNum) - parseInt(num1)) / newDenom;
            }
        }
        if(ans === question)
        {
            answerCounter++;
            basket.frame--;
            correctSfx.play();
            caught.updateTexture(1200,720);
            caught.play(false);
            document.body.style.cursor = "none";
            if(answerCounter <6)
            {
                displayQn();
            }
            else if(answerCounter == 6)
            {
                part = 2;
                getQuestion();
                halfWin.visible = true;
                fishy.forEach(function(fish)
                {
                    fish.visible = false;
                    dash1.visible = false;
                    dash2.visible = false;
                })
            }
            else if(answerCounter == 11)
            {
                if(level == 1)
                {
                    level2.visible = true;
                }
                else if(level == 2)
                {
                    playAgain.visible = true;
                }
                if(level == 3)
                {
                    level4.visible = true;
                }
                else if(level == 4)
                {
                    playAgain.visible = true;
                }
                winScreen.visible = true;
            }
            else if(answerCounter>6)
            {
                displayQn();
            }
        }
        else
        { 
            run.updateTexture(1200,720);
            run.play(false);
            document.body.style.cursor = "none";
            wrongSfx.play();
        }
//          game.randomizeFish();
    },

//  randomizeFish: function()
//  {       
//                answerTop1 = [3,4,5,4,3,3,3,4,3,6];
//  answerBot1 = [6,12,8,9,4,10,8,6,12,10];
//  answerTop2 = [5,11,7,8,8,8,7,7,10,9];
//  answerBot2 = [6,12,8,9,10,12,9,10,12,10];
//  answerTop3 = [1,1,3,1,1,1,2,4,2,1];
//  answerBot3 = [6,6,8,10,4,8,6,10,9,12];
//  answerTop4 = [3,8,1,5,3,3,3,8,1,1];
//  answerBot4 = [6,12,8,10,6,8,10,15,9,12];
//      /*
//      if(parseInt(denom1) > parseInt(denom2))
//      {
//          multiplier2 = denom1/denom2;
//          botSide = parseInt(denom1);
//          topSide = (parseInt(num2) * parseInt(multiplier2)) + parseInt(num1);
//      }
//      else if(parseInt(denom2) > parseInt(denom1))
//      {
//          multiplier2 = denom2/denom1;
//          botSide = parseInt(denom2);
//          topSide = (parseInt(num1) * parseInt(multiplier2)) + parseInt(num2);
//      }
//      */
//      for(var i = 0;i < 6;i++)
//      {
//          if(level == 1){
//          var randomNumber = game.rnd.integerInRange(0,answerTop1.length-1);
//                    }
//          else if(level == 2){
//          var randomNumber = game.rnd.integerInRange(0,answerTop2.length-1);
//                    }
//                        else if(level ==3){
//                         var randomNumber = game.rnd.integerInRange(0,answerTop3.length-1);
//                 }
//                else if(level ==4){
//                         var randomNumber = game.rnd.integerInRange(0,answerTop4.length-1);
//                     }
//                         
//          else 
//          {
//              if(part == 1 && level == 1)
//              {
//                  fishes[i].num = answerTop1.splice(randomNumber,1);
//                  fishes[i].denom = answerBot1.splice(randomNumber,1);
//              }
//              else if(part == 2 && level == 1)
//              {
//                  fishes[i].num = answerTop1.splice(randomNumber,1);
//                  fishes[i].denom = answerBot1.splice(randomNumber,1);
//              }
//              else if(part == 1 && level == 2)
//              {
//                  fishes[i].num = answerTop2.splice(randomNumber,1);
//                  fishes[i].denom = answerBot2.splice(randomNumber,1);
//              }
//              else if(part == 2 && level == 2)
//              {
//                  fishes[i].num = answerTop2.splice(randomNumber,1);
//                  fishes[i].denom = answerBot2.splice(randomNumber,1);
//              }
//                                 else if(part == 1 && level == 3)
//              {
//                  fishes[i].num = answerTop3.splice(theIndex,1);
//                  fishes[i].denom = answerBot3.splice(theIndex,1);
//              }
//              else if(part == 2 && level == 3)
//              {
//                  fishes[i].num = answerTop3.splice(theIndex+5,1);
//                  fishes[i].denom = answerBot3.splice(theIndex+5,1);
//              }
//                                else if(part == 1 && level == 4)
//              {
//                  fishes[i].num = answerTop4.splice(theIndex,1);
//                  fishes[i].denom = answerBot4.splice(theIndex,1);
//              }
//              else if(part == 2 && level == 4)
//              {
//                  fishes[i].num = answerTop4.splice(theIndex+5,1);
//                  fishes[i].denom = answerBot4.splice(theIndex+5,1);
//              }
//              textUp[i].setText(fishes[i].num);
//              textDown[i].setText(fishes[i].denom);
//              fishes[i].x = game.rnd.integerInRange(-300,-130);
//              fishes[i].y = game.rnd.integerInRange(150,500);
//              velo[i] = game.rnd.integerInRange(5,25)/10;
//          }
//          if(fishes[i].num < 10)
//          textUp[i].x = 60;
//          else if(fishes[i].num > 9)
//          textUp[i].x = 55;
//          if(fishes[i].denom > 9 && fishes[i].num <10)
//          textDown[i].x = 55;
//          else if(fishes[i].denom > 9 && fishes[i].num > 9)
//          textDown[i].x = 55;
//          else if(fishes[i].denom < 10)
//          textDown[i].x = 60;
//      }
//      
//      /*
//      fishy.forEach(function(fish)
//      {
//          var boundsA = fish.getBounds();
//          fishy.forEach(function(fish1)
//          {
//              var boundsB = fish1.getBounds();
//              if(Phaser.Rectangle.intersects(boundsA,boundsB) )
//              {
//                  fish.x = game.rnd.integerInRange(0,500);
//                  fish.y = game.rnd.integerInRange(150,500);
//              }
//          })
//      })
//      */
//  },

    test: function()
    {
        answerCounter++;

        if(answerCounter<6)
        displayQn();

        else if(answerCounter == 6)
        {
            part = 2;
            getQuestion();
        }
        else if(answerCounter > 6)
        {
            displayQn();
        }
    },

    closeInstructions: function()
    {
        instructionsBox.visible = false;
    },

    //Start Btn Function
    clickStart:function()
    {

    },

    //function to restart the game
    restartGame:function()
    {
        part = 1;
        this.state.start('StartScreen');
    },


    checkAnswer:function(fish)
    {
        fishy.forEach(function(fish)
        {
            if(game.input.mousePointer.isDown && fish.input.pointerOver() == true)
            {
                ans = parseInt(fish.num)/ parseInt(fish.denom);
            }
        })


    },


        //document.body.style.cursor = "url('resources/rod1.png'),wait";

        for(var i = 0; i < fishes.length; i++)
        {
            fishes[i].x += velo[i];

            if(fishes[i].y <= posY[i])
            {
                fishes[i].y += velo[i]/3;
            }
            else if(fishes[i].y >= posY[i])
            {
                fishes[i].y -= velo[i]/3;
            }

            if(fishes[i].x >= 1100)
            {
                velo[i] = game.rnd.integerInRange(5,25)/10;
                fishes[i].x = game.rnd.integerInRange(-300,-100);
                fishes[i].y = game.rnd.integerInRange(150,500);
                posY[i] = fishes[i].y + 100;
                offset[i] = game.rnd.integerInRange(500,1200);
            }
        }



        if(instructionsBox.visible == true && answerCounter == 1)
        {
            game.hideFish();
            dash1.visible = false;
            dash2.visible = false;
        }
        else if(instructionsBox.visible == false && answerCounter == 1)
        {
            game.showFish();
            dash1.visible = true;
            dash2.visible = true;
        }

        numerator1.setText(num1);
        numerator2.setText(num2);
        denominator1.setText(denom1);
        denominator2.setText(denom2);

        if(halfWin.visible == true && answerCounter == 6)
        {
            dash1.visible = false;
            dash2.visible = false;
            game.hideFish();
        }
        else if(halfWin.visible == false && answerCounter == 6)
        {
            dash1.visible = true;
            dash2.visible = true;
            game.showFish();
        }

        if(winScreen.visible == true)
        {
            dash1.visible = false;
            dash2.visible = false;
            game.hideFish();
        }
        if(worms.frame == 9 && winScreen.visible == false)
        {
            loseScreen.visible = true;
            dash1.visible = false;
            dash2.visible = false;
            game.hideFish();
        }
    },

    hideFish: function()
    {
        fishy.forEach(function(fish)
            {
                fish.visible = false;
            })
    },

    showFish: function()
    {
        fishy.forEach(function(fish)
            {
                fish.visible = true;
            })
    },

    //Rendering Qn based on the selected options
    renderQN:function()
    {

    },
    //Check obj out of bounds.
    outOfBound: function(item){


    },
    //Debug
    render: function()
    {

    }

}

I’m afraid this question is too “high level” so to speak. Not something in general with the Phaser library, but probably a mistake somewhere in your code. So AFAIK it’s impossible to answer without your code.

Only advice I can give is to break it up in pieces: Check step-for-step if the “generateNewQuestion” function works as expected. Then Check the “addFishes” method etc. Maybe force the game into an error situation, by starting with a question you know doesn’t work as expected.

Btw in your example screenshot the correct answer seems to be right there, 1/2 - 1/4 = 3/12 correct?

Perhaps you just need to reduce your fractions?

i.e.:
2/6 = 1/3
3/12 = 1/4
4/10 = 2/5

Here are the codes that might be the issue.

fishy = game.add.group();

            for(var i = 0;i < 10;i++)
            {
                game.colorPicker();
                var randomVelo = game.rnd.integerInRange(5,25);
                var randomIndex = game.rnd.integerInRange(120,500);
                var theX = game.rnd.integerInRange(-300,-120);
                var theY = randomIndex;
                var off = game.rnd.integerInRange(500,1200);
                posY[i] = theY + 100;
                if(level == 1)
                {
                    var randomNo = game.rnd.integerInRange(0,answerTop1.length-1);
                }
                if(level == 2)
                {
                    var randomNo = game.rnd.integerInRange(0,answerTop2.length-1);
                }
                if(level == 3)
                {
                    var randomNo = game.rnd.integerInRange(0,answerTop3.length-1);
                }
                if(level == 4)
                {
                    var randomNo = game.rnd.integerInRange(0,answerTop4.length-1);
                }

                else
                {
                    velo[i] = randomVelo / 10;
                    offset[i] = off;
                    fishes[i] = game.add.button(theX, theY,'fish2',game.next);
                    fishes[i].input.useHandCursor = false;
                    fishes[i].inputEnabled = true;
                    if(level == 1)
                    {
                        fishes[i].num = answerTop1.splice(randomNo,1);
                        fishes[i].denom = answerBot1.splice(randomNo,1);
                    }
                    else if(level == 2)
                    {
                        fishes[i].num = answerTop2.splice(randomNo,1);
                        fishes[i].denom = answerBot2.splice(randomNo,1);
                    }
                    else if(level == 3)
                    {
                        fishes[i].num = answerTop3.splice(randomNo,1);
                        fishes[i].denom = answerBot3.splice(randomNo,1);
                    }
                    else if(level == 4)
                    {
                        fishes[i].num = answerTop4.splice(randomNo,1);
                        fishes[i].denom = answerBot4.splice(randomNo,1);
                    }
                    fishes[i].animations.add('move',[0,1,2,3],5,true);
                    fishes[i].animations.play('move');


                    if(fishes[i].num < 10)
                    var textTop = game.add.text(60,30,fishes[i].num,style2);
                    else if(fishes[i].num > 9)
                    var textTop = game.add.text(55,30,fishes[i].num,style2);
                    if(fishes[i].denom > 9 && fishes[i].num <10)
                    var textBot = game.add.text(55,50,fishes[i].denom,style2);
                    else if(fishes[i].denom > 9 && fishes[i].num > 9)
                    var textBot = game.add.text(55,50,fishes[i].denom,style2);
                    else if(fishes[i].denom < 10)
                    var textBot = game.add.text(60,50,fishes[i].denom,style2);
                    var dash = game.add.sprite(55,53,'dash2');


                    textTop.stroke = "#000000";
                    textTop.strokeThickness = 5;
                    textBot.stroke = "#000000";
                    textBot.strokeThickness = 5;
                    fishes[i].addChild(textTop);
                    fishes[i].addChild(textBot);
                    fishes[i].addChild(dash);
                    textUp[i] = textTop;
                    textDown[i] = textBot;
                }
            }
        for(var i = 0;i<fishes.length;i++)
        {
            fishy.add(fishes[i]);
        }

        minus = game.add.sprite(30,-50,'minus');
        dash1.addChild(minus);
        minus.visible = false;

        plus = game.add.sprite(30,-50,'plus');
        dash1.addChild(plus);
        plus.visible = false;

        if(level == 1 || level == 2)
        {
            plus.visible = true;
            minus.visible = false;
        }
        else if(level == 3 || level == 4)
        {
            minus.visible = true;
            plus.visible = false;
        }

        dash1.scale.setTo(0.7);
        dash2.scale.setTo(0.7);


    },



    turnFish: function(fish)
    {
        switch(fish)
        {
            case 0:
            posY[fish] *= -1;
            timers[0] = game.time.now + game.rnd.integerInRange(500,1200);
            break;
            case 1:
            posY[fish] *= -1;
            timers[1] = game.time.now + game.rnd.integerInRange(500,1200);
            break;
            case 2:
            posY[fish] *= -1;
            timers[2] = game.time.now + game.rnd.integerInRange(500,1200);
            break;
            case 3:
            posY[fish] *= -1;
            timers[3] = game.time.now + game.rnd.integerInRange(500,1200);
            break;
            case 4:
            posY[fish] *= -1;
            timers[4] = game.time.now + game.rnd.integerInRange(500,1200);
            break;
            case 5:
            posY[fish] *= -1;
            timers[5] = game.time.now + game.rnd.integerInRange(500,1200);
            break;
        }
    }

    goTo2:function()
    {
        fishesx = [0,0,0,120,120,120,240,240,240,360,360,360,480,480,480,600,600,600];
        fishesy = [270,350,430,270,350,190,320,240,160,290,210,130,310,230,150,280,200,120];
        level = 2;
        part = 1;
        answerCounter = 1;
        reverseCounter = 0;
        fishes=[];
        goBack = false;
        this.game.state.start('Preloader');
    },
    goTo4:function()
    {
        fishesx = [0,0,0,120,120,120,240,240,240,360,360,360,480,480,480,600,600,600];
        fishesy = [270,350,430,270,350,190,320,240,160,290,210,130,310,230,150,280,200,120];
        level = 4;
        part = 1;
        answerCounter = 1;
        reverseCounter = 0;
        fishes=[];
        goBack = false;
        this.game.state.start('Preloader');
    },

    playAgain: function()
    {
        part = 1;
        level = 1;
        answerCounter = 1;
        fishes = [];
        reverseCounter = 0;
        goBack = false;
        fishesx = [0,0,0,120,120,120,240,240,240,360,360,360,480,480,480,600,600,600];
        fishesy = [270,350,430,270,350,190,320,240,160,290,210,130,310,230,150,280,200,120];
        answerTop1 = [3,4,5,4,3,3,3,4,3,6];
    answerBot1 = [6,12,8,9,4,10,8,6,12,10];
    answerTop2 = [5,11,7,8,4,2,7,7,5,9];
    answerBot2 = [6,12,8,9,5,3,9,10,6,10];
    answerTop3 = [1,1,3,1,1,1,2,4,2,1];
    answerBot3 = [6,6,8,10,4,8,6,10,9,12];
    answerTop4 = [3,8,1,5,3,3,3,8,1,1];
    answerBot4 = [6,12,8,10,6,8,10,15,9,12];
        values = [];
        this.game.state.start('StartScreen');
    },



        if(level == 1 || level == 2)
        {
            if(parseInt(denom2) > parseInt(denom1))
            {
                multiplier = parseInt(denom2)/parseInt(denom1);
                newNum = parseInt(num1)* multiplier;
                newDenom = parseInt(denom1) * multiplier;
                question = (parseInt(newNum) + parseInt(num2)) / newDenom;
            }
            else if(parseInt(denom2) < parseInt(denom1))
            {
                multiplier = parseInt(denom1)/parseInt(denom2);
                newNum = num2 * multiplier;
                newDenom = parseInt(denom2) * multiplier;
                question = (parseInt(newNum) + parseInt(num1)) / newDenom;
            }
        }
        else if(level == 3 || level == 4)
        {
            if(parseInt(denom2) > parseInt(denom1))
            {
                multiplier = parseInt(denom2)/parseInt(denom1);
                newNum = parseInt(num1)* multiplier;
                newDenom = parseInt(denom1) * multiplier;
                question = (parseInt(newNum) - parseInt(num2)) / newDenom;
            }
            else if(parseInt(denom2) < parseInt(denom1))
            {
                multiplier = parseInt(denom1)/parseInt(denom2);
                newNum = num2 * multiplier;
                newDenom = parseInt(denom2) * multiplier;
                question = (parseInt(newNum) - parseInt(num1)) / newDenom;
            }
        }
        if(ans === question)
        {
            answerCounter++;
            basket.frame--;
            correctSfx.play();
            caught.updateTexture(1200,720);
            caught.play(false);
            document.body.style.cursor = "none";
            if(answerCounter <6)
            {
                displayQn();
            }
            else if(answerCounter == 6)
            {
                part = 2;
                getQuestion();
                halfWin.visible = true;
                fishy.forEach(function(fish)
                {
                    fish.visible = false;
                    dash1.visible = false;
                    dash2.visible = false;
                })
            }
            else if(answerCounter == 11)
            {
                if(level == 1)
                {
                    level2.visible = true;
                }
                else if(level == 2)
                {
                    playAgain.visible = true;
                }
                if(level == 3)
                {
                    level4.visible = true;
                }
                else if(level == 4)
                {
                    playAgain.visible = true;
                }
                winScreen.visible = true;
            }
            else if(answerCounter>6)
            {
                displayQn();
            }
        }
        else
        { 
            run.updateTexture(1200,720);
            run.play(false);
            document.body.style.cursor = "none";
            wrongSfx.play();
        }
//          game.randomizeFish();
    },

//  randomizeFish: function()
//  {       
//                answerTop1 = [3,4,5,4,3,3,3,4,3,6];
//  answerBot1 = [6,12,8,9,4,10,8,6,12,10];
//  answerTop2 = [5,11,7,8,8,8,7,7,10,9];
//  answerBot2 = [6,12,8,9,10,12,9,10,12,10];
//  answerTop3 = [1,1,3,1,1,1,2,4,2,1];
//  answerBot3 = [6,6,8,10,4,8,6,10,9,12];
//  answerTop4 = [3,8,1,5,3,3,3,8,1,1];
//  answerBot4 = [6,12,8,10,6,8,10,15,9,12];
//      /*
//      if(parseInt(denom1) > parseInt(denom2))
//      {
//          multiplier2 = denom1/denom2;
//          botSide = parseInt(denom1);
//          topSide = (parseInt(num2) * parseInt(multiplier2)) + parseInt(num1);
//      }
//      else if(parseInt(denom2) > parseInt(denom1))
//      {
//          multiplier2 = denom2/denom1;
//          botSide = parseInt(denom2);
//          topSide = (parseInt(num1) * parseInt(multiplier2)) + parseInt(num2);
//      }
//      */
//      for(var i = 0;i < 6;i++)
//      {
//          if(level == 1){
//          var randomNumber = game.rnd.integerInRange(0,answerTop1.length-1);
//                    }
//          else if(level == 2){
//          var randomNumber = game.rnd.integerInRange(0,answerTop2.length-1);
//                    }
//                        else if(level ==3){
//                         var randomNumber = game.rnd.integerInRange(0,answerTop3.length-1);
//                 }
//                else if(level ==4){
//                         var randomNumber = game.rnd.integerInRange(0,answerTop4.length-1);
//                     }
//                         
//          else 
//          {
//              if(part == 1 && level == 1)
//              {
//                  fishes[i].num = answerTop1.splice(randomNumber,1);
//                  fishes[i].denom = answerBot1.splice(randomNumber,1);
//              }
//              else if(part == 2 && level == 1)
//              {
//                  fishes[i].num = answerTop1.splice(randomNumber,1);
//                  fishes[i].denom = answerBot1.splice(randomNumber,1);
//              }
//              else if(part == 1 && level == 2)
//              {
//                  fishes[i].num = answerTop2.splice(randomNumber,1);
//                  fishes[i].denom = answerBot2.splice(randomNumber,1);
//              }
//              else if(part == 2 && level == 2)
//              {
//                  fishes[i].num = answerTop2.splice(randomNumber,1);
//                  fishes[i].denom = answerBot2.splice(randomNumber,1);
//              }
//                                 else if(part == 1 && level == 3)
//              {
//                  fishes[i].num = answerTop3.splice(theIndex,1);
//                  fishes[i].denom = answerBot3.splice(theIndex,1);
//              }
//              else if(part == 2 && level == 3)
//              {
//                  fishes[i].num = answerTop3.splice(theIndex+5,1);
//                  fishes[i].denom = answerBot3.splice(theIndex+5,1);
//              }
//                                else if(part == 1 && level == 4)
//              {
//                  fishes[i].num = answerTop4.splice(theIndex,1);
//                  fishes[i].denom = answerBot4.splice(theIndex,1);
//              }
//              else if(part == 2 && level == 4)
//              {
//                  fishes[i].num = answerTop4.splice(theIndex+5,1);
//                  fishes[i].denom = answerBot4.splice(theIndex+5,1);
//              }
//              textUp[i].setText(fishes[i].num);
//              textDown[i].setText(fishes[i].denom);
//              fishes[i].x = game.rnd.integerInRange(-300,-130);
//              fishes[i].y = game.rnd.integerInRange(150,500);
//              velo[i] = game.rnd.integerInRange(5,25)/10;
//          }
//          if(fishes[i].num < 10)
//          textUp[i].x = 60;
//          else if(fishes[i].num > 9)
//          textUp[i].x = 55;
//          if(fishes[i].denom > 9 && fishes[i].num <10)
//          textDown[i].x = 55;
//          else if(fishes[i].denom > 9 && fishes[i].num > 9)
//          textDown[i].x = 55;
//          else if(fishes[i].denom < 10)
//          textDown[i].x = 60;
//      }
//      
//      /*
//      fishy.forEach(function(fish)
//      {
//          var boundsA = fish.getBounds();
//          fishy.forEach(function(fish1)
//          {
//              var boundsB = fish1.getBounds();
//              if(Phaser.Rectangle.intersects(boundsA,boundsB) )
//              {
//                  fish.x = game.rnd.integerInRange(0,500);
//                  fish.y = game.rnd.integerInRange(150,500);
//              }
//          })
//      })
//      */
//  },

    test: function()
    {
        answerCounter++;

        if(answerCounter<6)
        displayQn();

        else if(answerCounter == 6)
        {
            part = 2;
            getQuestion();
        }
        else if(answerCounter > 6)
        {
            displayQn();
        }
    },

    closeInstructions: function()
    {
        instructionsBox.visible = false;
    },

    //Start Btn Function
    clickStart:function()
    {

    },

    //function to restart the game
    restartGame:function()
    {
        part = 1;
        this.state.start('StartScreen');
    },


    checkAnswer:function(fish)
    {
        fishy.forEach(function(fish)
        {
            if(game.input.mousePointer.isDown && fish.input.pointerOver() == true)
            {
                ans = parseInt(fish.num)/ parseInt(fish.denom);
            }
        })


    },


        //document.body.style.cursor = "url('resources/rod1.png'),wait";

        for(var i = 0; i < fishes.length; i++)
        {
            fishes[i].x += velo[i];

            if(fishes[i].y <= posY[i])
            {
                fishes[i].y += velo[i]/3;
            }
            else if(fishes[i].y >= posY[i])
            {
                fishes[i].y -= velo[i]/3;
            }

            if(fishes[i].x >= 1100)
            {
                velo[i] = game.rnd.integerInRange(5,25)/10;
                fishes[i].x = game.rnd.integerInRange(-300,-100);
                fishes[i].y = game.rnd.integerInRange(150,500);
                posY[i] = fishes[i].y + 100;
                offset[i] = game.rnd.integerInRange(500,1200);
            }
        }



        if(instructionsBox.visible == true && answerCounter == 1)
        {
            game.hideFish();
            dash1.visible = false;
            dash2.visible = false;
        }
        else if(instructionsBox.visible == false && answerCounter == 1)
        {
            game.showFish();
            dash1.visible = true;
            dash2.visible = true;
        }

        numerator1.setText(num1);
        numerator2.setText(num2);
        denominator1.setText(denom1);
        denominator2.setText(denom2);

        if(halfWin.visible == true && answerCounter == 6)
        {
            dash1.visible = false;
            dash2.visible = false;
            game.hideFish();
        }
        else if(halfWin.visible == false && answerCounter == 6)
        {
            dash1.visible = true;
            dash2.visible = true;
            game.showFish();
        }

        if(winScreen.visible == true)
        {
            dash1.visible = false;
            dash2.visible = false;
            game.hideFish();
        }
        if(worms.frame == 9 && winScreen.visible == false)
        {
            loseScreen.visible = true;
            dash1.visible = false;
            dash2.visible = false;
            game.hideFish();
        }
    },

    hideFish: function()
    {
        fishy.forEach(function(fish)
            {
                fish.visible = false;
            })
    },

    showFish: function()
    {
        fishy.forEach(function(fish)
            {
                fish.visible = true;
            })
    },

    //Rendering Qn based on the selected options
    renderQN:function()
    {

    },
    //Check obj out of bounds.
    outOfBound: function(item){


    },
    //Debug
    render: function()
    {

    }

}