Web Tech Tute 3
Web Tech Tute 3
Question 1)
function palindromeCheck(number) {
if (number < 0) {
return false;
}
let original = number;
let reversed = 0;
console.log(palindromeCheck(121));
console.log(palindromeCheck(12321));
console.log(palindromeCheck(12345));
--------------------------------------------------------------
Question 3)
<!DOCTYPE html>
<html>
<head>
<title>HTML Calculator</title>
input[type="button"] {
width: 100%;
padding: 20px 40px;
background-color: green;
color: white;
font-size: 24px;
font-weight: bold;
border: none;
border-radius: 5px;
}
input[type="text"] {
padding: 20px 30px;
font-size: 24px;
font-weight: bold;
border: none;
border-radius: 5px;
border: 2px solid black;
}
</style>
</head>
<body>
<tr>
<td><input type="button" value="1"></td>
<td><input type="button" value="2"></td>
<td><input type="button" value="3"></td>
<td><input type="button" value="/"></td>
</tr>
<tr>
<td><input type="button" value="4"></td>
<td><input type="button" value="5"></td>
<td><input type="button" value="6"></td>
<td><input type="button" value="*"></td>
</tr>
<tr>
<td><input type="button" value="7"></td>
<td><input type="button" value="8"></td>
<td><input type="button" value="9"></td>
<td><input type="button" value="-"></td>
</tr>
<tr>
<td><input type="button" value="0"></td>
<td><input type="button" value="."></td>
<td><input type="button" value="="></td>
<td><input type="button" value="+"></td>
</tr>
</table>
</body>
</html>
----------------------------------------------------------------------
QUESTION 4)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Change Font on Hover</title>
<style>
/* Initial style for the text */
.text {
font-family: Arial, sans-serif;
font-size: 24px;
}
</style>
</head>
<body>
<script>
// Get the element
const textElement = document.getElementById('textElement');
textElement.addEventListener('mouseout', function() {
// Reset the font when the mouse leaves the text
textElement.style.fontFamily = 'Arial, sans-serif';
});
</script>
</body>
</html>
----------------------------------------------------------------------
QUESTION 5
AJAX is essential for creating efficient, dynamic, and responsive web applications,
especially in Single Page Applications (SPAs).
-----------------------------------------------------------------------
QUESTION 6
Step 1: Event Triggers AJAX Call: AJAX calls are typically triggered by events on
the webpage,
such as a button click, text input, or page load.
Step 2: XMLHttpRequest Object: JavaScript creates an XMLHttpRequest object, which
is
configured with the server's endpoint URL, the HTTP method (usually GET or POST),
and any
required parameters.
Step 3: Sending the Request: Once the request is set up, it’s sent to the server
using
xhr.send().
Step 4: Server Processes Request: The server processes the request, performs the
necessary
actions (like querying a database), and sends back a response (often in JSON
format).
Step 5: JavaScript Handles the Response: JavaScript receives and processes the
response
using event listeners (e.g., onload). The page is then updated dynamically,
typically by
modifying the DOM.
-------------------------------------------------------------------------------
QUESTION 7
- **IPv4 (Internet Protocol version 4)** is the most commonly used and consists of
32 bits, expressed as four decimal numbers separated by dots (e.g., 192.168.1.1).
- **IPv6** uses 128 bits, written as eight groups of hexadecimal numbers separated
by colons, and is designed to address the limited number of IPv4 addresses.
IP addresses are classified into several categories based on their usage and the
range of addresses they represent:
1. **Class A**:
- Range: 1.0.0.0 to 127.255.255.255
- Default Subnet Mask: 255.0.0.0
- Used for large networks, with the first octet identifying the network.
2. **Class B**:
- Range: 128.0.0.0 to 191.255.255.255
- Default Subnet Mask: 255.255.0.0
- Used for medium-sized networks, with the first two octets identifying the
network.
3. **Class C**:
- Range: 192.0.0.0 to 223.255.255.255
- Default Subnet Mask: 255.255.255.0
- Used for smaller networks, with the first three octets identifying the
network.