From 6932a4b2ae75e16403dd1a508a08158dd87807c3 Mon Sep 17 00:00:00 2001 From: HomamS Date: Wed, 2 Oct 2019 13:03:33 -0400 Subject: [PATCH] Week-10 Practice Done --- index.html | 33 +++++++++++++++++++++++++++++++++ practice.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 index.html create mode 100644 practice.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..c19085b --- /dev/null +++ b/index.html @@ -0,0 +1,33 @@ + + + + + + + + + + + + +

+ +
+ First name:
+ Last name:

+ + +
+ + + + diff --git a/practice.js b/practice.js new file mode 100644 index 0000000..1dbfbfc --- /dev/null +++ b/practice.js @@ -0,0 +1,28 @@ +//Create a JavaScript code with global and local variable. Call your local variable outside of its function. Why do you receive an error? +let number = 0; +function myFunction(){ + let x = 5; +} +// console.log(x); + +// because variable x is block scope + +//Create a program where a button acts like a counter. Everytime an user clicks on it, it counts up (starting from 0). Make sure you use closures (create two functions, one outer and one inner). + +function counter(){ + let number = 0; + function increment(){ + number++; + console.log(number); + return number; + } + return increment; +} +let z = counter(); +document.getElementById('click').addEventListener('click', z); + +//Problem 3: Create a program with a button. When an user clicks on the button, the program executes an alert stating “the user has clicked!” + +document.getElementById('Hamam').addEventListener('click', function(){ + alert('the user has clicked!') +});