Question-1: Part (A)
Question-1: Part (A)
Part(a):
<script>
var message="Thanks,";
var userName = "Susan";
var banger="!";
var customMess = message+userName +banger+""+String(42);
alert(customMess);
</script>
Part(b):
<script>
var dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var now =new Date();
var theDay=now.getDay();
var nameOftoday=dayNames[(theDay+1)%7];
alert(nameOftoday);
</script>
Part(c):
<script>
function duplicate(arr){
return arr.concat(arr);
}
console.log("Duplicate Array:",duplicate([1,2,3,4,5]));
</script>
Part(d):
<script>
var string = "Welcome to this Javascript Guide!";
function reverseBySeparator(string, separator) {
return string.split(separator).reverse().join(separator); }
var reverseEntireSentence=reverseBySeparator(string, ""); \\ this line reverse all the character in
the string
var reverseEachWord= reverseBySeparator(reverseEntireSentence, ""); \\ reverse each word
within reversed string, so we need to one statement/line if we want to reverse our string
console.log("Reversed Each Word:", reverseEachWord);
console.log("Reversed Entire Sentence:", reverseEntireSentence);
</script>
Part(e):
<script>
function decimalToBinary(digit){
if(digit<0){
return "Invalid Input";
}
else if(digit===0){
return "0";
}
else if (digit >= 1){
if (digit % 2){
return decimalToBinary((digit-1)/2)+1;
}
else{
// Recursively return proceeding binary digits
return decimalToBinary(digit/2)+"0";
}}
else {
return"";}
}
console.log("Binary of -5", decimalToBinary(-5));
console.log("Binary of 0", decimalToBinary(0));
console.log("Binary of 3", decimalToBinary(3));
console.log("Binary of 8", decimalToBinary(8));
console.log("Binary of 1000", decimalToBinary(100));
</script>
Question-2:
<!DOCTYPE html>
<html>
<head>
<title>Modified Document</title>
</head>
<body>
<header>
<h1>Welcome to My Simple Document</h1>
</header>
<div>
<p>There's not much to this, but now It has a header</p>
<div>
<section>
<h2>Additional Sections/h2>
<p>This is some new content in another section.</p>
</section>
<footer>
<p>Thanks for visiting!</p> </footer>
</body>
</html>
DOM structure:
Level 0: <!DOCTYPE html> (It is a root of document structure but not part of the DOM
tree)
Level 1: <html> (root of the DOM tree)
Level 2: <head> <body> (Children of <html> )
Level 3: <title> (Children of head), <header> <div> <section><footer> (Children of
Body)
Level 4: text nodes <h1> <p>
HTML
Head Body
H1 P H2 P P
Question-4:
MYSQL:
Create database UniversityManagementSystem;
CREATE TABLE Employee(
employee_id int AUTO_INCREMENT PRIMARY KEY,
name varchar(30) not null,
department varchar(30),
position varchar(30)
);
CREATE TABLE Student(
student_id int AUTO_INCREMENT PRIMARY KEY,
name varchar(30) not null,
course varchar(30),
employee_id int,
FOREIGN key (employee_id) REFERENCES employee(employee_id)
);
CREATE TABLE Faculty(
faculty_id int AUTO_INCREMENT PRIMARY KEY,
name varchar(30) not null,
subject varchar(30),
employee_id int,
FOREIGN key (employee_id)REFERENCES employee(employee_id)
);
Create Database connection with PHP:
<?php
$host="localhost";
$username="root";
$password="";
$dbname="universitymanagementsystem";
$conn=new mysqli($host,$username,$password,$dbname);
if($conn->connect_error){
die("Connection failed:" .$conn->connect_error);
}
else
{
echo "Connection Successful";
}
?>
Question-5:
Associative array in PHP:
<?php
$users=[
"user1"=>["name"=>"Hamza", "email"=>"[email protected]"],
"user2"=>["name"=>"Ali", "email"=>"[email protected]"],
];
echo "user1's email" .$users["$user1"]["$email"]. "<br>";
echo "User Profile" ;
foreach($users as $username =>$details)
{
echo "Username:$username";
foreach($details as $key =>$value){
echo $key .":" .$value. "<br>";
}
}
?>
<html>
<head>
</head>
<body>
<script>
const users={
user1:{name:"Hamza", email:"[email protected]"},
user2:{name:"Ali", email:"[email protected]"},
};
console.log("User1 email:" +users.user1.email);
console.log("User Profile");
for (var username in users){
console.log("Username:" +username);
for (var key in users[username]){
console.log(`${key.slice(1)}:${users[username][key]}`);
}
console.log("");
}
</script>
</body>
</html>