Doesn't work in an actual HTML form

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/2/5?curriculum_id=506324b3a7dffd00020bf661

<In what way does your code behave incorrectly? Include ALL error messages.>
I have worked through the functions exercise but when I try pacing the code for example lesson 12 in a HTML page (outside CodeCademy) it does NOT work. Its all well and good learning things in CodeCademy but how about applying them in a HTML page. How do we do that?

```

Here is my entire HTML and it outputs NOTHING!!

<do not remove the three backticks above>

instead of giving the function return output you need to specify were to add it to the html. try to create a

in body with an id then set the destination to out put to with document.getElementById(“id”). innerHTML = sleepstatus;

check out this link
w3schools

sorry was supposed to be a paragraph tag but didn’t show up here

<DOCTYPE html>
<html>
<head>
<script type="text/javascript">

 var sleepCheck = function (numHours) {
    var sleepStatus = ""
    if (numHours >= 8) {
        sleepStatus = "You're getting plenty of sleep! Maybe even too much!";
    }
    else {
        sleepStatus = "Get some more shut eye!";
    }
   document.getElementById("demo").innerHTML = sleepStatus;
};
</script>
</head>
<body onload="sleepCheck(10);">
<p id="demo"></p>
</body>
</html>
1 Like

@ajfarroll
apart what @cfecteau1 presented
you could instead of your
return sleepStatus;
use
alert(sleepStatus);
or if you use the HTML-Debugger you could read the console
after using
console.log(sleepStatus);

1 Like

Thanks to all who responded. I am beginning to doubt the use of return value from javascript in HTML. However I resolved it by placing this in the body.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.