Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions week10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

/*Problem 1:
Create a JavaScript code with global and local variable. Call your local
variable outside of its function. Why do you receive an error?
*/

//local variable
let course= "Programing";
function myFunction() {
let courseName = "some stuff";

}
//console.log(courseName);
//it is an error because the variable that inside the function no one can get to it.


//2Problem 2:
//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).
let outerFunction = function (){
let number = 0;
return function(){
number++;
return number;
}
}();

document.getElementById("dd").addEventListener('click', function(){

document.getElementById("display").innerHTML= outerFunction();


});



/*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('alert').addEventListener('click', function(){
alert("the user has clicked!");
});

/*4- Create a form where the user is asked to enter their first and last name.
Also, create a reset button, so that when an user clicks reset, the form is reset
(their input is deleted).
this can be done by button type if I use it like this type="reset"
if you want it in javaScript so this is the code*/

document.getElementById('del').addEventListener('click', function(one){
one.preventDefault();

document.getElementById('for').reset();

});
80 changes: 80 additions & 0 deletions week10html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<!DOCTYPE html>
<html>
<head>
<script src="week10.js" defer></script>
<title>

Week 10 Practice
</title>
</head>

<body>

<h1> PROBLEM QUISTIONS </h1>



<h2>Quistion 2</h2>

<button id="dd">Click here</button>

<p id='display'></p>

<h2>Quistion 3</h2>



<div>




Create a program with a button. When an user clicks on the button,<br>
the program executes an alert stating “the user has clicked!<br>
</div>
<br>

<button id="alert">Click here</button>






<h2>Quistion 4</h2>
<div>
Create a form where the user is asked to enter their first and last name.<br>
Also, create a reset button, so that when an user clicks reset,<br>
the form is reset(their input is deleted).
</div>

<br>

<form id="for">
<input id="firtsName" placeholder="First Name">
<input id="lastName" placeholder=" Last Name">

<button id="submit">Submit</button>
<button id="del">Reset</button>

</form>





<h2>Quistion 5</h2>

<div>
Consider the code below. Try running this code in your browser.<br>
You will be outputted with an error. Fix the code so “Welcome Guest” appears.
</div>







</body>
</html>