dimanche 23 juillet 2017

Guessing the number in javascript

I'm all day trying to make a guessing game number in javascript, but I can not. Can you help me?

Adivinhe o número

    <div class="main">
        <div class="container">
            <div class="row">
                <form class="form">
                    <div class="col-xs-8 col-md-10">
                        <input id="comment" type="text" placeholder="Tente um número:">
                    </div>
                    <div class="col-xs-4 col-md-2">
                        <button type="submit" class="btn">post</button>
                    </div>
                </form>
            </div>

            <ul class="comments" id="comments">
                <li></li>
                <li></li>
            </ul>

        </div>
    </div>

    <script src="http://ift.tt/1N7dbW8"></script>
    <script src="script.js"></script>

var main = function() {

$('form').submit(function(event) {
    var $input = $(event.target).find('input');
    var comment = $input.val();

    if (comment != "") {
        var html = $('<li>').text(comment);
        html.prependTo('#comments');
        $input.val("");
    }

    return false;
});

}

$(document).ready(main);

var answer = comment; var number = confirm(Math.round(Math.random()*10)); answer=parseInt(answer); if (number === answer) { confirm("You win!"); } else if(number < answer){ confirm("Your number was too low!"); } else if (number > answer) { confirm("Your number was too high!"); }




Aucun commentaire:

Enregistrer un commentaire