Run scripts created in the html from html

0

I'm starting with the issue of scripts in html and I can not get this to work:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Tests</title>
        <script>
            readvalue();
            sum();
            result();
        </script>
    </head>
    <body>      
        <script>
            function readvalue(){
                var string = window.prompt("Enter the information", "");
            }

            function sum(string){
            }
        </script>
    </body>
</html>

I missed the error in the browser:

  

Uncaught ReferenceError: readvalue is not defined

I also need to work with that string in two more functions. Any help on how to handle this?

    
asked by David_helo 15.10.2018 в 20:15
source

1 answer

1

You have to declare functions first and then call them like this:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Tests</title>
</head>
<body>

    <script>
    
    
    function readvalue(){
      var string = window.prompt("Enter the information", "");
      return string;
    }

    function sum(string){
      alert(string);
    }
    
    var valor = readvalue();
    
    if(valor != null){
      sum(valor);
    }
    //result();

    </script>

</body>
</html>

The result() function does not exist.

    
answered by 15.10.2018 / 20:18
source