Get value of variable from function for use in another function (JavaScript)

Answer for this question


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

    <button type="button" name="button" onclick="firstFunc()">Click me</button>
    <button type="button" name="button" onclick="secondFunc()">Click me</button>
    <script type="text/javascript">
    var x = 0;
    function firstFunc(){
        x = 1
    }

    function secondFunc(){
        alert(x);
    }
    </script>
  </body>
</html>

Comment whether this answer is correct or not.

Comments

Popular posts from this blog

Artificial Intelligence

The taxonomy of CASE Tools

Zoho Second round - adding a digit to all the digits of a number