0

HTML File:

    <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script src="jquery.js"></script>

<div id="question">  
            <img id="fruit1" class="fruit">  
        </div>

I removed duplicates Separate file for explode effect. jquery.js not a jquery library sorry for the confusion

var playing = false;
var score;
var trialsleft;
var step;
var action;
var fruits = ["apple", "arbuzas", "avocado", "banana", "berry", "carrot", "lemon", "pumpkin", "tomato"]

$(function(){ // Click on start reset button
    $("#startreset").click(function(){

        // We are 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");

            // Start sending fruits
            startAction();
        }
    });
   $("#fruit1").mouseover(function(){
    score++;
    $("#scorevalue").html(score); //Update score
    document.getElementById("sliceSound").play(); // Play Sound
    // $("#sliceSound")[0].play();

    //Stop Fruit 
    clearInterval(action);

    //Hide Fruit
    $("#fruit1").hide("explode", 500); // Slice fruits

    //Send new fruit
    setTimeout(startAction, 500);
});

I add top of my code, thanks for any help and support. I got functions below this code, but I'm not sure if it problem with that and should i post it here because it to long wont let me.

Justas
  • 19
  • 6
  • 2
    So why are you including jQuery multiple times? That final include (``) is going to remove the ui from the plugin. – Taplar Nov 29 '18 at 20:18
  • Actually with the first script, you're including it three times .... – Taplar Nov 29 '18 at 20:19
  • I write on separate files. – Justas Nov 29 '18 at 20:21
  • What do you mean by that? Is jquery.js not the jquery library? – Taplar Nov 29 '18 at 20:22
  • No, I just name it a file like that. – Justas Nov 29 '18 at 20:24
  • 1
    You should reconsider that, given the confusion it can cause. Other than that, why are you including two version of jquery in the page? Also please edit your question to show the contents of the `jquery.js` file – Taplar Nov 29 '18 at 20:24
  • Thank you, Did it. – Justas Nov 29 '18 at 20:32
  • Your logic is not in a document ready and it is included above the markup it manipulates – Taplar Nov 29 '18 at 20:34
  • Possible duplicate of [Why does jQuery or a DOM method such as getElementById not find the element?](https://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element) – Taplar Nov 29 '18 at 20:35
  • Try removing the number 500 in `$("#fruit1").hide("explode", 500);` and just use `$("#fruit1").hide("explode");` – Dumisani Nov 29 '18 at 20:37
  • @Dumisani that's not the issue. It's an ordering issue. The logic is not in a document ready and the script runs before the element is parsed into the DOM – Taplar Nov 29 '18 at 20:40
  • I add top of my code. Removed number 500, still same problem – Justas Nov 29 '18 at 20:47

0 Answers0