Git Product home page Git Product logo

js-guess-game's Introduction

Guessing Game!

  1. Create a file, guess.html, well-formed HTML document
  • an input field with an id of "guess-number" (this input field is NOT inside a form, its just hanging out by itself)
  • a button that says "Guess!" with an id of "submit-guess"
  • a div with an id of "results"
  1. Include this link to the jQuery library in the head of your HTMl file:
  • <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  1. Include a tag in your HTML document that links to another file, guess.js
  2. Create a file, guess.js with:
  • The "document ready" function
  1. Inside the document ready function we will:
  • generate a random number, 1-10 and store it in a variable, number
  const number = Math.floor((Math.random() * 10) + 1);
  • write a function that:
    • listens to the click of the "submit-guess" button
    • grabs the value of the "guess-number" input
    • compares the that number to the random number we generated
    • updates the "results" section of the page with "You won!" or "You lost!" depending on whether or not the guess matched the number you generated.
$(document).ready(function() {
const number = Math.floor((Math.random() * 10) + 1);
$("guess-btn").on('click', function(e) {
  e.preventDefault()
  let guess = $("guess-number").val();
  if (guess === number) {
    $("results").html("YOU WIN")
  } else {
    $("results").html("YOU LOOSE")
  }
})
})

js-guess-game's People

Contributors

sophiedebenedetto avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

cgyork

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.