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.
<!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
Post a Comment