Why didn't this js output what was expected?

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>test</title>
</head>
<body>


<button id="test" onclick="doit()">click</button>
<P id="num">4</P>
<script>

    function doit() {
        var value = document.getElementById("num").innerText;
        document.write(value)
        if (value > 3) {
            document.getElementById("num").innerHTML= 50;
        } else {
            document.getElementById("num").innerHTML=590;
        }

    }
</script>

</body>
</html>

Why can"t the code after adding document.write (value); be executed?

Mar.04,2021

because this document.getElementById ("num") no longer exists.

document.write (value) is output directly to body .

  

you have rewritten the page

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-16de8a6-88f0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-16de8a6-88f0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?