GithubHelp home page GithubHelp logo

numero-secreto's Introduction

This JavaScript code represents a simple guessing game where the player needs to guess a secret number. Let's break it down:

  1. Variables Initialization:

    • listaDeNumerosSorteados: An empty array to store the drawn numbers.
    • numeroLimite: Defines the upper limit for the range of numbers the player can guess.
    • numeroSecreto: Holds the secret number randomly generated.
    • tentativas: Keeps track of the number of attempts the player has made.
  2. Helper Functions:

    • exibirTextoNaTela(tag, texto): Displays text on the webpage by selecting an HTML element with the provided tag and updating its content with the given text.
    • exibirMensagemInicial(): Displays the initial message to the player, prompting them to choose a number between 1 and 10.
    • limparCampo(): Clears the input field after each guess.
    • gerarNumeroAleatorio(): Generates a random secret number within the defined range and ensures it has not been previously drawn.
  3. Event Handling Functions:

    • verificarChute(): Called when the player submits their guess. It compares the guess with the secret number and provides feedback. If the guess is correct, it displays a success message along with the number of attempts and enables the option to restart the game. If the guess is incorrect, it provides a hint about whether the secret number is higher or lower and increments the number of attempts.
    • reiniciarJogo(): Resets the game by generating a new secret number, clearing the input field, resetting the number of attempts, and displaying the initial message.
  4. Initial Execution:

    • Calls exibirMensagemInicial() to display the initial message.
  5. HTML Integration:

    • The HTML elements <h1>, <p>, and <input> are targeted by the JavaScript functions to display messages, take input, and display the game status.

Overall, this code creates a basic guessing game where the player needs to guess a secret number within a certain range, providing feedback after each guess until the correct number is guessed.

numero-secreto's People

Contributors

marcosmalheiros avatar

Watchers

 avatar

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.