Giter Site home page Giter Site logo

cvcastano / guess-the-number Goto Github PK

View Code? Open in Web Editor NEW
1.0 0.0 0.0 13 KB

Result of the 2nd module evaluation exercise during the bootcamp at Adalab. Created by GitHub Classroom

Home Page: https://cvcastano.github.io/guess-the-number/

HTML 33.37% JavaScript 46.49% CSS 20.14%

guess-the-number's Introduction

modulo-2-evaluacion-intermedia-cvcastano

modulo-2-evaluacion-intermedia-cvcastano created by GitHub Classroom

guess-the-number's People

Contributors

cvcastano avatar

Stargazers

Adriana Del Teso avatar

guess-the-number's Issues

Code comments and improvements

Really cool job @cvcastano !!!

Here you have some tips to improve the exercise:

JavaScript: basic

  • Extract the feedback painter to a function.
  • Check what the user has typed and if it really is a number
  • Don't use an element to resolve the counter, a good old variable will suffice ;)
  • Remove debugger and other unnecessary code

JavaScript: advanced

  • You are writing many times "trackEl.innerHTML = 'something';", what about making a function that accepts a string as param and paints it into 'trackEl'?
  • Use ev.preventDefault() to prevent page reload.
  • Move ev.preventDefault() to first line of the function.

Good practices

  • Try to improve your commits messages. "Add JS" is a bit poor. "Add random number logic" is more explanatory.

HTML

  • Add form
  • Use a label to define the content of the input.
  • Connect the label to the input using the for attribute of the label and the id of the input.
  • Use placeholder.

Steps to finish the game (for those far from the solution)

You are close to the exercise solution, but here you have a steps guide to complete it anyway ;)

  1. Save a reference to DOM elements in variables.
  2. Generate the random number and save it to a variable.
  3. Init counter of trials to 0.
  4. Define a function that executes when the user clicks on the button, that
  • increments the counter and paints its value in the HTML.
  • collect the value of the HTML input and compare it with the random number.
    • if they are equal, draw a 'You Win' message.
    • if it's lower, draw a 'Too short' message.
    • if it's higher, draw a 'Too long' message.
  1. Assign a listener to the button click to execute the previous function.

Further challenges

Then you can improve the game as you please, here you have some ideas:

  • Add new feedback when the number is bigger than 100 or smaller than 0.
  • Manage when the user hits the button and the input is empty.
  • Make the input work when hitting enter key.
  • Add a reset button that cleans the input, the counter, writes the initial feedback and generates a new random number to play again!
  • Whatever you want!

Call to action

Let me know if you have any doubts ;)

Go for it!!

Do not close this issue until your teacher asks you to

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.