I was trying to add 1 to the number 0, every time I click on the paragraph, using the “onclick” keyword.
9128 was added to “a” every time I clicked on the paragraph, instead of 1.
The code is as follows and I have attached the screenshots.
<!DOCTYPE html>
<html>
<head>
<title>trial.html</title>
</head>
<body>
<p id="output" onclick="change_paragraph_text()"> Default Text </p>
<script type="text/javascript">
var a = 0;
function change_paragraph_text() {
document.getElementById("output").innerHTML = a;
a++;
change_paragraph_text();
}
var name = "Lohith";
document.write(name);
</script>
</body>
</html>