Q&A for How to Add JavaScript to Your Website Using HTML

Return to Full Article

Search
Add New Question
  • Question
    How can I add code, like variables, or draw functions?
    Incognito sam
    Community Answer
    Inside the tags, you can write regular JavaScript code that will be run when the page loads. To add a variable, simply do something like this: let x = 5; console.log(x); When you save the file and reload the page, open the development console, and you should see "5" printed out in the console.
  • Question
    How do I fix error alerts on JavaScript?
    D7mtg
    Community Answer
    You need to run a debugger. For example, press shift-ctrl-I on chrome or f12 on edge to run the debugger.
  • Question
    Can I see all of the JavaScript code when I add it using HTML?
    Community Answer
    Yes , All javascript codes are in between OR tag.
  • Question
    How can I add a picture?
    ModMaker
    Community Answer
    Use imgur.com to upload a picture and copy the direct link. Then on your HTML maker, make an HTML block. Copy and paste the direct link from Imgur in between those two tags.
  • Question
    How do I add PHP in HTML documents?
    Community Answer
    Verify that PHP is installed on the web server. Make sure that the HTML document has a PHP extension (i.e. mypage.php). Then, add your PHP code directly in the page. With JavaScript it's impossible, because PHP is server-side, JavaScript isn't.
  • Question
    How do I add multiple pictures to JavaScript?
    Community Answer
    To add a picture inside the script tags (using javascript of course) you need to load an image from your computer. Ex) var image = new Image(); Be sure to use the value new Image(). The variable name can change. Then, source the image. Ex.) image.src = 'image_file_name_here.png'; The word image before .src should be the name of the previously declared variable containing the new image() value. Finally, draw the image. This requires some knowledge of how to manipulate the website canvas, which cannot be explained here as it is quite long. There are very good sources on the web explaining how to draw images and pictures.
  • Question
    Can I make a JavaScript document using HTML?
    Stockriderj
    Community Answer
    You can make a JavaScript script, but not a file. HTML is a markup language, technically; not a coding language. You can't exactly do math with it.
  • Question
    How is it helpful to use JavaScript?
    Stockriderj
    Community Answer
    JavaScript can change elements on a webpage, not just do very complicated math. This means that it's very powerful as it can control the page and modify it with the input. You could make, for example, a button that you click to add another square to the page. The possibilities are basically endless!
  • Question
    How to generate random numbers using HTML?
    Stockriderj
    Community Answer
    HTML cannot generate random numbers, but with an embedded JavaScript script, it can. In order to generate a random number, you just need to type: Math.round(Math.random() * [max number])
  • Question
    What are the canvas sizes when adding JavaScript to my website using HTML?
    Monredo
    Community Answer
    The default size of the canvas is 300 pixels × 150 pixels (width × height). But custom sizes can be defined using the HTML height and width property.
Ask a Question

      Return to Full Article