Professional Documents
Culture Documents
ITL 226
Lab Journal 6
Student Name: MUHAMMAD ABDULLAH WASEEM
Enrolment No: 01-135222-048
Class and Section : BS(IT) -5A
Objectives:
To Learn how to apply JavaScript arrays and objects.
Tools Used:
Submission Date:
Using JavaScript print your name, University, Degree and Occupation as paragraph and on console.
Procedure/Program:
1) <!DOCTYPE html>
<html>
<body>
<script>
document.write("<p>University: BUIC</p>");
document.write("<p>Degree: IT</p>");
document.write("<p>Occupation: Student</p>");
</script>
</body>
</html>
2)
<!DOCTYPE html>
<html>
<body>
<script>
console.log("University: BUIC");
console.log("Degree: IT");
console.log("Occupation: Student");
</script>
</body>
</html>
Task # 2:
Write JS code to get the length of a JavaScript array and length of Javascript object.
Procedure/Program:
2) const person = {
age: 30,
};
Task # 3:
Write JS code to alphabetically sort, concatenate and add elements to an array in Javascript.
Procedure/Program:
console.log(allFruits);
Task # 4:
Write JS code showing coordinates (in a div/textbox/any container) of mouse pointer changing its
position in browser. (Hint: Use Mouse Event for it).
Procedure/Program:
HTML:
<!DOCTYPE html>
<html>
<body>
</canvas>
</body>
</html>
JAVASCRIPT:
canvas.addEventListener('mousemove', function(event) {
const x = event.clientX;
const y = event.clientY;
});
Task # 5:
Suppose you have following paragraph. Add following CSS attributes to modify the paragraph using
JavaScript.
<script>
</script>
c. Use the HTML DOM to change the text size of <p> to 30 pixels.
d. Use the HTML DOM to hide / unhide the <p> element when a “toggle” button is clicked.
Procedure/Program:
HTML:
<!DOCTYPE html>
<html>
<head>
<style>
p{
text-align: center;
font-size: 20px;
</style>
</head>
<body>
<button onclick="toggleParagraph()">Toggle</button>
<script src="script.js"></script>
</body>
</html>
JAVASCRIPT:
para.style.backgroundColor = 'orange';
para.style.textAlign = 'left';
// c. Use the HTML DOM to change the text size of <p> to 30 pixels.
para.style.fontSize = '30px';
// d. Use the HTML DOM to hide / unhide the <p> element when a “toggle” button is clicked.
function toggleParagraph() {
para.style.display = 'block';
} else {
para.style.display = 'none';