Learning to pull data from a form with JS

I’m teaching myself Javascript and for my first attempt at applying some concepts I made a basic number guessing game. I can’t seem to get it to work though! Would someone mind taking a look and helping me figure out where I’ve gone wrong? It’s very VERY basic and I’m sure there’s some simple concept I haven’t learned or have overlooked.

I’m trying to get the user to guess the number 6!

var myNum = 6;
var userGuess = document.getElementById("number").value;
if (userGuess == myNum) {
            writeMessage('statusArea', '<p>"You guessed my favorite number!"</p>');}
  if (userGuess > myNum) {
            writeMessage('statusArea', '<p>"Nope, too high, try again!"</p>');}
if (userGuess < myNum) {
            writeMessage('statusArea', '<p>"Nope, too low, try again!"</p>');}
<header>Can you guess my favorite number?</header>
<body>
  <form><label for="number">Enter a number here:</label><br>
    <input type="text" id="number" name="number"><br><input type="submit" value="Guess"></form> 
  
  <div id="statusArea"></div>
</body>

https://codepen.io/The_vagabond_blonde/pen/KKNgOrm

142 thoughts on “Learning to pull data from a form with JS”

  1. When I initially left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and from now on every time
    a comment is added I receive four emails with the same
    comment. Is there a means you can remove me from that service?

    Kudos!

    Reply
  2. Woah! I’m really enjoying the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s hard to get that “perfect balance” between user friendliness and appearance.
    I must say you have done a amazing job with this. Also, the blog loads extremely fast
    for me on Firefox. Superb Blog!

    Reply
  3. Greetings from Colorado! I’m bored to tears at work so I decided to check out your site on my iphone during lunch break.

    I enjoy the information you provide here and can’t wait to take a look when I get
    home. I’m surprised at how fast your blog loaded on my phone ..
    I’m not even using WIFI, just 3G .. Anyhow, excellent blog!

    Reply
  4. Excellent goods from you, man. I have understand your stuff previous to and you’re just too fantastic.

    I actually like what you have acquired here, certainly like what
    you are saying and the way in which you say
    it. You make it entertaining and you still care for to keep it wise.

    I can’t wait to read far more from you. This is
    really a great site. quest bars http://bitly.com/3C2tkMR quest bars

    Reply
  5. My developer is trying to convince me to move
    to .net from PHP. I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been using WordPress on a number of websites for about a
    year and am concerned about switching to another platform.
    I have heard very good things about blogengine.net.
    Is there a way I can transfer all my wordpress content into it?
    Any help would be greatly appreciated! scoliosis surgery https://0401mm.tumblr.com/ scoliosis surgery

    Reply
  6. Undeniably believe that which you stated. Your favorite reason appeared
    to be on the internet the simplest thing to be aware of.

    I say to you, I certainly get irked while people
    think about worries that they plainly don’t know about.
    You managed to hit the nail upon the top and also defined out the
    whole thing without having side effect , people could take a
    signal. Will probably be back to get more. Thanks ps4 games https://bitly.com/3nkdKIi ps4 games

    Reply
  7. Hello. This post couldn’t be written any better! Reading this post reminds me of my previous room mate. He always kept chatting about this. I will forward this page to him. Fairly certain he will have a good read. Thank you for sharing.

    Reply

Leave a Comment