crop_rotate
Run
<!DOCTYPE html> <html> <body> <h2>JavaScript Function Closures</h2> <p>Counting with a global variable.</p> <p id="demo"></p> <script> // Initiate counter let counter = 0; // Function to increment counter function add() { counter += 1; } // Call add() 3 times add(); add(); add(); // The counter should now be 3 document.getElementById("demo").innerHTML = "The counter is: " + counter; </script> </body> </html>
PCFET0NUWVBFIGh0bWw+DQo8aHRtbD4NCjxib2R5Pg0KDQo8aDI+SmF2YVNjcmlwdCBGdW5jdGlvbiBDbG9zdXJlczwvaDI+DQo8cD5Db3VudGluZyB3aXRoIGEgZ2xvYmFsIHZhcmlhYmxlLjwvcD4NCg0KPHAgaWQ9ImRlbW8iPjwvcD4NCg0KPHNjcmlwdD4NCi8vIEluaXRpYXRlIGNvdW50ZXINCmxldCBjb3VudGVyID0gMDsNCg0KLy8gRnVuY3Rpb24gdG8gaW5jcmVtZW50IGNvdW50ZXINCmZ1bmN0aW9uIGFkZCgpIHsNCiAgY291bnRlciArPSAxOw0KfQ0KDQovLyBDYWxsIGFkZCgpIDMgdGltZXMNCmFkZCgpOw0KYWRkKCk7DQphZGQoKTsNCg0KLy8gVGhlIGNvdW50ZXIgc2hvdWxkIG5vdyBiZSAzDQpkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgiZGVtbyIpLmlubmVySFRNTCA9ICJUaGUgY291bnRlciBpczogIiArIGNvdW50ZXI7DQo8L3NjcmlwdD4NCg0KPC9ib2R5Pg0KPC9odG1sPg==