0
<!DOCTYPE html>
<html>

<body>
<p>Click the button to display a random number between 1 and 10.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = Math.floor((Math.random() * 10) + 1);
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

I created a html file on dreamweaver, but it said that I have error and I can't find the error, help!!!

2 Answers2

1

By using the W3C Validator at http://validator.w3.org/#validate_by_input I was able to see the validation error.

Copied from W3C.org:

 Line 4, Column 6: Element head is missing a required instance of child element title.

These errors will not affect the literal usability of your application but it is always a good idea to do your best to not have any validation errors in your HTML. I am not an HTML validation expert but if you do not have valid HTML, some browsers may not act as you designed.

I suggest you use the W3C.org validator often to verify your code.

sauv0168
  • 93
  • 8
0

in some old ver. IE, code need to like this:

<script><!--
function myFunction() {
    var x = Math.floor((Math.random() * 10) + 1);
    document.getElementById("demo").innerHTML = x;
}
//--></script>
Walter
  • 1
  • 1
  • This is not necessary, and hasn't been for about a decade. See http://stackoverflow.com/questions/808816/are-html-comments-inside-script-tags-a-best-practice. –  Jan 23 '15 at 04:30