diff --git a/index.html b/index.html new file mode 100644 index 0000000..7888437 --- /dev/null +++ b/index.html @@ -0,0 +1,51 @@ + + + + + + + + + + + + +
+ +
+
+ +

Number of clicks: 0

+
+ +
+ + First name:
+ Last name:
+ + + +
+ + +

+
+ +

+ + + +
+ + + diff --git a/script.js b/script.js new file mode 100644 index 0000000..99f2cbe --- /dev/null +++ b/script.js @@ -0,0 +1,37 @@ +//Problem 1 + +var obj1 = "I am global"; +function check(){ + var obj2 = "I am local"; +} + +console.log(obj1); +console.log(obj2); + +/* We got an error because. We can't reach local variables outside of the function. + They can only be accessed from within the function. */ + +//Problem 2 + +var counter = 0; + function onClick() { + counter += 1; + document.getElementById("clicks").innerHTML = counter; + }; + + //Problem 3 + + function alertFunction(){ + alert("the user has clicked!") + } + + document.getElementById("clickbutton").addEventListener("click", alertFunction); + + //Problem 4 + + function nameFunction() { + var x = document.getElementById("nameForm"); + document.getElementById("demo").innerHTML = x; + + document.getElementById("nameForm").reset(); + }