Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  • Thread Tools
  • Rate This Thread
  1. #1
    New to the CF scene
    Join Date
    May 2016
    Location
    Ann Arbor
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    "Sams Teach Yourself Beginning Programming..." Page 16. button doesn't work

    Hello,
    I wrote my first program, and it opens ok, but when I click on the button, nothing happens. To me, everything looks good, but obviously, other than spelling and punctuation, I don't know what to look for.

    Here is what I have:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <script>
    
    /* This is the function that gets
    called when the user clicks the
    button on the main page */
    
    function displayAnswer ()
    {
    document . write(“Just 24 1-hour lessons!”);
    }
    </script>
    </head>
    <body>
    
    
    <h1>My First Program</h1>
    <p id=“demo”>How long will it take for me to learn to program?</p>
    
    <button type=“button” onclick=“displayAnswer ()”>How many hours?<button/button>
    
    </body>
    </html>
    That's the whole program.

    The <button> should open a new window with the reply "just 24 1-hour lessons".

    I don't know what brackets {} or parentheses () are for, and sometimes its hard to tell if there is a space in a code, or not.

    Also, I tried to enable the Apple Safari Debugger, according to online directions, but I guess I don't know enough about "Terminal" to get it going.

    So, my main question is, if it's not a blatant typo, such as <buton>, then what else stops the program in its tracks?

    Thank you,

    David Paris
    Ann Arbor
    Last edited by vinyl-junkie; 05-09-2016 at 04:26 AM. Reason: added code tags

  2. #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    4,595
    Thanks
    14
    Thanked 480 Times in 475 Posts
    So, my main question is, if it's not a blatant typo, such as <buton>, then what else stops the program in its tracks?
    it’s a combination of blatant typo (using typographical quotes instead of straight quotes, in both HTML and JS) and the use of document.write(), which—according to definition—erases your document.

    PS. you don’t need the Terminal to open Safari’s dev tools. just cmd+alt+i (after you enabled debugging mode in the Safari settings).
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  3. #3
    New to the CF scene
    Join Date
    May 2016
    Location
    Ann Arbor
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    it’s a combination of blatant typo (using typographical quotes instead of straight quotes, in both HTML and JS) and the use of document.write(), which—according to definition—erases your document.

    PS. you don’t need the Terminal to open Safari’s dev tools. just cmd+alt+i (after you enabled debugging mode in the Safari settings).

    I increased my font size to 48 so I could see what my quote marks looked like. I noticed that when I typed a quote ("), it had the appearance of what you might call a "straight" quote, but in a fraction of a second it automatically changed to what you could probably call a "typographical" quote. It did this little magic trick whether or not the box was checked in Preferences for "Smart quotes"- whatever that means.

    I don't understand why this book doesn't describe the importance of quotation marks and other incidentals to get a person rolling right off the bat!

    Any other suggestions?

  4. #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,482
    Thanks
    57
    Thanked 633 Times in 628 Posts
    Quote Originally Posted by parisda View Post
    I increased my font size to 48 so I could see what my quote marks looked like. I noticed that when I typed a quote ("), it had the appearance of what you might call a "straight" quote, but in a fraction of a second it automatically changed to what you could probably call a "typographical" quote. It did this little magic trick whether or not the box was checked in Preferences for "Smart quotes"- whatever that means.

    I don't understand why this book doesn't describe the importance of quotation marks and other incidentals to get a person rolling right off the bat!

    Any other suggestions?
    sounds to me like you might be using a word processing program to write your code, which is a fabulously bad idea. I use the free notepad++ program for windows. If you're on Mac, apparently Sublime Text is a good alternative but I have never tried it.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •