Home > Articles > Web Development

  • Print
  • + Share This
This chapter is from the book

Q&A

  • Q. Do I need to test my JavaScript on more than one browser?

    A. In an ideal world, any script you write that follows the standards for JavaScript will work in all browsers, and 98% of the time (give or take) that’s true in the real world. But browsers do have their quirks, and you should test your scripts in Chrome, Internet Explorer, and Firefox at a minimum.

  • Q. If I plan to learn PHP, Ruby, or some other server-side programming language anyway, will I have any use for JavaScript?

    A. Certainly. JavaScript is the ideal language for many parts of a web-based application, such as form validation. Although PHP, Ruby, and other server-side languages have their uses, they can’t interact directly with the user on the client side.

  • Q. When I try to run my script, the browser displays the actual script in the browser window instead of executing it. What did I do wrong?

    A. This is most likely caused by one of three errors. First, you might be missing the beginning or ending <script> tags. Check them, and verify that the first reads <script type="text/javascript">. Second, your file might have been saved with a .txt extension, causing the browser to treat it as a text file. Rename it to .htm or .html to fix the problem. Third, make sure your browser supports JavaScript, and that it is not disabled in the Preferences dialog.

  • Q. Why are the <strong> and <br /> tags allowed in the statements to print the time? I thought HTML tags weren’t allowed within the <script> tags.

    A. Because this particular tag is inside quotation marks, it’s considered a valid part of the script. The script’s output, including any HTML tags, is interpreted and displayed by the browser. You can use other HTML tags within quotation marks to add formatting, such as the <h2> tags we added for the large clock display.

  • + Share This
  • 🔖 Save To Your Account