Professional Documents
Culture Documents
Q1. What will be the output of the following HTML and CSS
snippet?
Answer: a) Two boxes, one red and one blue, each 50px by
50px
Q2. Match the following HTML tags with their correct
descriptions:
Answer: a1, b3, c4, d2
<a>: Used for linking to other pages or resources
<div>: Non-semantic container for other elements
<script>: Embeds JavaScript code or files
<table>: Used to create tables
Q3. What does the following CSS selector target?
Answer: a) All elements with class item directly inside the
element with ID container
JavaScript Section
Q4. What will be the output of the following JavaScript code
snippet?
Answer: c) '22'
Explanation: In JavaScript, adding a number and a
string will result in string concatenation.
Q5. Which statement about JavaScript promises is true?
Answer: a) A promise can only be resolved once.
Explanation: A promise represents a value that may
be available now, in the future, or never, and once
settled (either resolved or rejected), it cannot change
its state.
Q6. Match the following JavaScript methods with their
descriptions:
Answer: a4, b2, c1, d3
Array.map(): Creates a new array with the results of
calling a function for every array element
Array.filter(): Creates a new array with elements that
pass a test
Array.forEach(): Executes a function for each array
element without returning
Array.reduce(): Reduces the array to a single value
Q7. Given the following code, what will be logged to the
console?
Answer: b) 20
Explanation: The changeX function changes the value
of x to 20, and this change is reflected when x is
logged to the console.
JavaScript Solutions
Task 1: Change Text Color on Click
htmlCopy code
<p id="text">Click me to change my color.</p> <script>
document.getElementById("text").addEventListener("click",
function() { this.style.color = 'blue'; }); </script>
Task 2: Load JSON Data and Display
htmlCopy code
<div id="data"></div> <script>
fetch('https://jsonplaceholder.typicode.com/posts/1') .then(res
ponse => response.json()) .then(json =>
{ document.getElementById("data").innerText = json.title; });
</script>
Task 3: Toggle Visibility of an Element
htmlCopy code
<button id="toggleButton">Toggle Div</button> <div
id="toggleDiv">This is a toggleable div.</div> <script>
document.getElementById("toggleButton").addEventListener("
click", function() { var div =
document.getElementById("toggleDiv"); div.style.display =
div.style.display === "none" ? "block" : "none"; }); </script>
jQuery Solutions
Task 1: Animate an Element
htmlCopy code
<button id="animateButton">Animate Div</button> <div
id="animateDiv" style="background-color: lightblue; height:
100px; width: 100px;"></div> <script> $
('#animateButton').click(function() { $
('#animateDiv').animate({ height: '200px', width: '200px' }); });
</script>
Task 2: AJAX Request to Load Data
htmlCopy code
<button id="loadDataButton">Load Data</button> <div
id="content"></div> <script> $
('#loadDataButton').click(function() { $.ajax({ url:
'https://jsonplaceholder.typicode.com/posts/1', type: 'GET',
success: function(response) { $
('#content').text(response.title); } }); }); </script>
Task 3: Append List Items
htmlCopy code
<button id="addItemButton">Add List Item</button> <ul
id="myList"> <li>List Item 1</li> </ul> <script> $
('#addItemButton').click(function() { $
('#myList').append('<li>New Item</li>'); }); </script>