Is there any error ? And how to include this code to an html document ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is there any error ? And how to include this code to an html document ?

// program to generate a multiplication table // take input from the user let number = parseInt(prompt('Enter an integer: ')); //creating a multiplication table for(let i = 1; i <= 10; i++) { // multiply i with number result = i * number; // display the result console.log(`${number} * ${i} = ${result}`); } How to include it in an html document please nd is there any error ? This is my first program with js

17th Oct 2020, 2:18 PM
Samah Mamour
9 Answers
+ 1
If you're planning to do this in Code Playground, then you can paste the above code (just the code) in the JS section of a web code. You can also embed it in a script block in an HTML document if you' re doing this on your own PC / laptop. Put the script block in between the /body and /html No error as I tested it, except that it outputs the table into the JS console. Not that is a big problem, but you better learn how to output into the document body, by updating some element's content (can be done later).
17th Oct 2020, 3:31 PM
Ipang
+ 1
Thank you so much
17th Oct 2020, 3:33 PM
Samah Mamour
+ 1
Ipang i just want to ask you about the extension when there is some Javascript code inside an HTML document is it .js or .html ?
17th Oct 2020, 4:17 PM
Samah Mamour
+ 1
Use .htm or .html as the extension for the HTML document. Use .js as extension for the Javascript file. This is a file that contains Javascript code only, can't mix HTML code inside it. We still save a HTML document by .html even if we have embedded Javascript inside it ...
17th Oct 2020, 4:29 PM
Ipang
+ 1
Then it's. HTML cause i didn't an external reference
17th Oct 2020, 4:32 PM
Samah Mamour
+ 1
Yes, it will be .html when no external reference used in HTML document 👍
17th Oct 2020, 4:34 PM
Ipang
+ 1
I see thank you a lot 👍
17th Oct 2020, 4:35 PM
Samah Mamour
0
Do you understand what I wrote? It is most important that you do. If you still got any doubt, don't hesitate, just ask away ...
17th Oct 2020, 3:39 PM
Ipang
0
Ok happy coding 😊
17th Oct 2020, 4:37 PM
Ipang