意外的字符串?

时间:2016-03-28 14:26:36

标签: jquery

我遇到了一个问题,我似乎无法找到意想不到的字符串......遗憾的是我似乎无法找到它!有谁知道'意外字符串'在哪里?如果需要,我可以发布我的HTML和CSS代码:)

谢谢你们!

var playing = false;
var score;
var trialsLeft;
var step;
var action; //used for setInterval function
var fruits = ['pear', 'peach', 'watermelon'];
    $(function () {
        //click on start reset button
        $("#startreset").click(function(){

            //are we playing?
            if(playing == true){

                //reload page
                location.reload();

            }else{

                //we are not playing
                playing = true; //game initiated

                //set score to 0
                score = 0;
                $("#scorevalue").html(score);

                //show trials left
                $("#trialsLeft").show();
                trialsLeft = 3;
                addHearts();

                //hide game over box
                $("#gameOver").hide();

            //change button text to reset game
                $("#startreset").html("Reset Game");

            //
            startAction();

            }       
        });

            //yes
                //reload page
            //no
                //1. create a random fruit
                //define a random step
                //2. move fruit down by 1 step every 30 sec
                    //is fruit too low?
                        //no-> repeat number 2.
                        //yes-> do we have trials left?
                            //yes-> repeat number 1.
                            //no-> show "game over"

    //slice a fruit
        //play sound
        //explode fruit

    //functions

    function addHearts(){
            for(i = 0; i < trialsLeft; i++){
                    $("#trialsLeft").empty();
                    $("#trialsLeft").append('<img src="images/heart.png" class="life">');
    }
        }
    //start sending fruits

    function startAction(){

        //generate a fruit
        $("#fruit1").show();
        chooseFruit(); //choose a random fruit
        $("#fruit1").css({'left' : Math.round(550*Math.random()), 'top' : -50});
        //random position

        //generate a random step (speed)
        step = 1+ Math.round(5*Math.random()); // change step

        //Move fruit down by one step every 10ms
        action = setInterval(function(){
            $("#fruit1").css('top', $("#fruit1").position().top + step);//move fruits by step

            //check if fruit is too low
            if ($("#fruit1").position().top > $("#fruitsContainer").height()) {

                //check if we have trials left
                if(trialsLeft > 1 ) {
                    $("#fruit1").show();
        chooseFruit(); //choose a random fruit
        $("#fruit1").css({'left' : Math.round(550* Math.random()), 'top' : -50});
        //random position

        //generate a random step (speed)
        step = 1 + Math.round(5*Math.random()); // change step
                //reduce trials by one
                trialsLeft --;

                    //populate trialsLeft box
                    addHearts();

                }else{ //game over
                    playing = false; //we are not playing anymore
                    $("#startreset").html("Start Game"); //change button to Start Game
                    $("#gameOver").show();
                    ($"#gameOver").html('<p>Game Over!</p><p>Your score is '+ score +'</p>');
                    $("#trialsLeft").hide();
                    stopAction();
                }
            }
        }, 10);
    }

    //generate a random fruit

    function chooseFruit(){
        $("#fruit1").attr('src' , 'images/' + fruits[Math.round(3*Math.random())] + '.png');
    }

    //stop dropping fruits
    function stopAction(){
        clearInterval(action);
        $("#fruit1").hide();
    }
    });

1 个答案:

答案 0 :(得分:1)

代码应为$("#gameOver").html('<p>Game Over!</p><p>Your score is ' + score + '</p>');

$是游戏结束ID(("#gameOver")

的选择器)