problem with array

Discussion in 'JavaScript' started by ssimon171078, May 21, 2015.

  1. #1
    i wrote js.script +html page problem to insert values of array into $("p").eq(i).text();
    my array is
    var number1=(Math.floor(Math.random() * 50) + 1);
    var number2=(Math.floor(Math.random() * 25) + 1);
    var number3= 100-(number1+number2);
    var num=new Array(number1,number2,number3);
    num.push(50,100,25,7);
    my files game .js
    /**
    * Created by User on 01.11.14.
    */
    
    var result = 0;
    var  flagClick=3;
    var flagLevel=1;
    /*======================================*/
    $(document).ready(function(){
    
    
        $("p").click(function(){
            $(this).css({"background-color": "green"});
    
            var t= $(this).text();
            sum(t);
        });
        for(i=1;i<=8;i++){
            $("p").eq(i).text();
            if(i<=4){
                $("p").eq(i).css("display","block");
            }
        }
    
    });
    /*  -----  eta functia sumiruet nash resultat */
    function sum(num){
        var res = parseInt(num);
        if(flagLevel==1){
            if( flagClick==0){
                alert("Ti praigral");
               window.open("joaca.html","_parent");
    
            }else{
                flagClick--;
                result = eval (result +res);
                if(result==100){
                    alert("Congratulations, you got the correct amount !!!");
                    flagLevel=2;
                    flagClick=3;
                    result=0;
                    /*---- zagrujaem document i atabrajaem ishi dve(total=6) knopchi vmeste s verhnii p---*/
                    $(document).ready(function(){
                        $("p#text").text("Add three numbers that their outcome will be equal to 450 !!!!");
                        $("div p").css({"margin-top": "1em","margin-left": "1.5em"});
                        $("p").css({"background-color": "red"});
                        $("p#text").css({"background-color": "chartreuse", "border": "0.2em solid red" });
                        $("p").eq(5).css("display","block");
                        $("p").eq(6).css("display","block");
                    });
                }else if(result>=100){
                    alert("Summa nevernaya");
                    window.open("joaca.html","_parent");
                }
            }
        }else if(flagLevel==2){
            if( flagClick==0){
                alert("Ti praigral");
                window.open("joaca.html","_parent");
            }else{
                flagClick--;
                result = eval (result +res);
                if(result==450){
                    alert("Congratulations, you got the correct amount !!!");
                    flagLevel=3;
                    flagClick=2;
                    result=1;
                    /*---- zagrujaem document i atabrajaem ishi dve(total=8) knopchi vmeste s verhnii p---*/
                    $(document).ready(function(){
                        $("p#text").text("Two numbers that multiply their result to be in 2500 !!!! ");
                        $("div p").css({"margin-top": "0.8em","margin-left": "0.8em"});
                        $("p").css({"background-color": "red"});
                        $("p#text").css({"bakground-color":"aqya","border": "0.2em solid red"});
                        $("p").eq(7).css("display","block");
                        $("p").eq(8).css("display","block");
    
                    });
                }else if(result>=450){
                    alert("Summa nevernaya");
                    window.open("joaca.html","_parent");
                }
            }
        }else if(flagLevel==3){
            if( flagClick==0){
                alert("Ti praigral");
                window.open("joaca.html","_parent");
            }else{
                flagClick--;
                result = (result*res);
                if(result==2500){
                    $(document).ready(function(){
                        $("html").html('<!DOCTYPE html>' +
                            ' <html> ' +
                            ' <head>' +
                            ' <title>Playing with adding numbers</title>' +
                            ' <link rel="stylesheet" href="style.css">'+
                            '</head>' +
                            '<body bgcolor="#56aaff"!important> ' +
                            '<p id="finish"> Congratulations !!! You have reached the end of the game !!!</p>' +
                            '</body>' +
                            '</html>');
                    });
                }else if(result>=2500){
                    alert("Summa nevernaya");
                    window.open("joaca.html","_parent");
                }
            }
        }
    }
    
    Code (JavaScript):
    game.html:
     <!DOCTYPE html>
    <html>
    <head>
        <title>Playing with adding numbers</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
       
        <script type="text/javascript" src="game.js"></script>
        <link rel="stylesheet" href="style.css">
    
    </head>
    <body >
    <p id="text">Add three numbers that their outcome will be equal to 100 !!!!</p>
    
    <div id="aa">
        <p>10</p>
        <p>40</p>
        <p>50</p>
        <p>50</p>
        <p>100</p>
        <p>25</p>
        <p>7</p>
        <p>5</p>
    
    </div>
    
    </body>
    </html>
    HTML:
    style.css:
    /**
    * Created by User on 01.11.14.
    * The CSS  Stylesheet document
    */
    div{
        padding: 4em;
    
    }
    
    p:hover {
        background-color: yellow;
    }
    div p{
        text-align: center;
        margin-top: 1em;
        margin-left: 3em;
        float: left;
        display: none;
        height: 1.8em;
        width: 1.8em;
    }
    
    #text{
        background-color: aqua;
        border: 0.2em solid chartreuse;
       
    }
    
    
    p{
        background-color: red;
        /*text-shadow: 0.1em -0.1em 0 red;*/
        font-size: 3em;
        border: 0.2em solid chartreuse;
       
    }
    
    body{
    
        background-color: pink;
        text-align: center;
    }
    
    
    #finish{
        text-align: center;
        color: #56aaff;
        background-color: yellow;
        font-size: 3em;
    
    }
    
    Code (CSS):

     
    ssimon171078, May 21, 2015 IP