0% found this document useful (0 votes)
52 views14 pages

DOCTYPE HTML

The documents discuss various JavaScript and PHP concepts. The JavaScript documents cover built-in objects like Math, Date, Number, Array, and String and how to use their properties and methods. The PHP documents demonstrate basic syntax like variables, constants, loops and cookies.

Uploaded by

Sukruthi Kc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views14 pages

DOCTYPE HTML

The documents discuss various JavaScript and PHP concepts. The JavaScript documents cover built-in objects like Math, Date, Number, Array, and String and how to use their properties and methods. The PHP documents demonstrate basic syntax like variables, constants, loops and cookies.

Uploaded by

Sukruthi Kc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

<!

DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Array Literals in JSON</title>

</head>

<body>

<h1>Array Literals in JSON</h1>

<p id="output"></p>

<script>

let myArray = ["Sukruthi", "KC", 22, true];

document.getElementById("output").innerHTML = JSON.stringify(myArray);

</script>

</body>

</html>
<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Object Literals in JSON</title>

</head>

<body>

<h1>Object Literals in JSON</h1>

<p id="output"></p>

<script>

let myObject = {

firstName: "Sukruthi",

lastName: "KC",

age: 22,

isMale: false

};

document.getElementById("output").innerHTML = JSON.stringify(myObject);

</script>

</body>

</html>
<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Mixing Literals in JSON</title>

</head>

<body>

<h1>Mixing Literals in JSON</h1>

<p id="output"></p>

<script>

let myObject = {

firstName: "Sukruthi",

lastName: "KC",

age: 22,

hobbies: ["reading", "swimming", "hiking"],

address: {

street: "123 Main St",

city: "Bengaluru",

state: "Karnataka",

zip: "12345"

};

document.getElementById("output").innerHTML = JSON.stringify(myObject);

</script>

</body>
</html>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>XML program with RAW XML content display</title>

</head>

<body>

<h1>XML program with RAW XML content display</h1>

<pre>

<?xml version="1.0" encoding="UTF-8"?>

<note>

<to>Shubha</to>

<from>Sukruthi</from>

<heading>Reminder</heading>

<body>Don't forget the meeting</body>

</note>
</pre>

</body>

</html>

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xml>

<html>

<head>

<title>My XML Document</title>

<style>

/* define styles for XML elements */

xml {

font-size: 16px;

font-family: Arial, sans-serif;

color: #333;

element {

font-size: 14px;
font-weight: bold;

color: #555;

margin-bottom: 10px;

attribute {

font-size: 12px;

font-style: italic;

color: #777;

</style>

</head>

<body>

<xml>

<element>

<attribute name="id">1</attribute>

<attribute name="type">book</attribute>

<title>The Lord of the Rings: The Fellowship of the Ring</title>

<author>J.R.R. Tolkien</author>

<publisher>Houghton Mifflin Harcourt</publisher>

</element>

</xml>

</body>

</html>
Math Object
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Math</title>
</head>
<body>
<script>
document.write(Math.abs(-5));
document.write("<br>");
document.write(Math.ceil(3.14));
document.write("<br>");
document.write(Math.floor(3.14));
document.write("<br>");
document.write(Math.max(1,5,10));
document.write("<br>");
document.write(Math.min(1,5,10));
</script>
</body>
</html>

Output

Date Object
<!DOCTYPE html>
<html>
<head>
<title>date objects</title>
</head>
<body>
<script>
const now=new Date()
document.write(now.getDate());
document.write("<br>");
document.write(now.getMonth());
document.write("<br>");
document.write(now.getMinutes());
document.write("<br>");
now.setDate(20);
document.write(now.getDate());
document.write("<br>");
now.setMonth(4);
document.write(now.getMonth());
</script>
</body>
</html>

Output

Number Object
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Number Objects</title>
</head>
<body>
<script>
document.write("JavaScript Number Objects")
document.write("<br>");
const num=42;
document.write(num.toExponential(2));
document.write("<br>");
document.write(num.toFixed(2));
document.write("<br>");
document.write(num.toString());
document.write("<br>");
document.write(num.toPrecision(4));
document.write("<br>");
document.write(num.valueof());
</script>
</body>
</html>

Output

Array Object
<!DOCTYPE html>
<html>
<head>
<title>Array Methods in JavaScript</title>
</head>
<body>
<script>
var fruits = ["Apple", "Banana", "Cherry", "Date", "Elderberry"];
document.write("<p>Original Array: " + fruits + "</p>");
fruits.push("Fig");
document.write("<p>After push(): " + fruits + "</p>");
fruits.pop();
document.write("<p>After pop(): " + fruits + "</p>");
fruits.shift();
document.write("<p>After shift(): " + fruits + "</p>");
fruits.unshift("Apricot");
document.write("<p>After unshift(): " + fruits + "</p>");
fruits.sort();
document.write("<p>After sort(): " + fruits + "</p>");
</script>
</body>
</html>

Output

String Object
<!DOCTYPE html>
<html>
<head>
<title>String Object in JavaScript</title>
</head>
<body>
<script>
var str = "Hello, world!";
document.write("<p>Original String: " + str + "</p>");
var upper = str.toUpperCase();
document.write("<p>Uppercase String: " + upper + "</p>");
var lower = str.toLowerCase();
document.write("<p>Lowercase String: " + lower + "</p>");
var length = str.length;
document.write("<p>Length of String: " + length + "</p>");
var substr = str.substring(0, 5);
document.write("<p>Substring of String: " + substr + "</p>");
</script>
</body>
</html>

<!DOCTYPE html>

<html>
<head>

<title>JavaScript Built-in Objects</title>

<script>

// Math Object

console.log(Math.PI); // 3.141592653589793

console.log(Math.ceil(4.3)); // 5

console.log(Math.floor(4.9)); // 4

// Date Object

let today = new Date();

console.log(today); // Wed Apr 27 2023 11:30:35 GMT-0700 (Pacific Daylight Time)

console.log(today.getFullYear()); // 2023

// Number Object

let x = 123.456;

console.log(x.toExponential(2)); // 1.23e+2

console.log(x.toFixed(2)); // 123.46

// Array Object

let fruits = ["apple", "banana", "cherry"];

console.log(fruits.length); // 3

fruits.push("date");

console.log(fruits); // ["apple", "banana", "cherry", "date"]

// String Object
let greeting = "Hello, world!";

console.log(greeting.length); // 13

console.log(greeting.toUpperCase()); // HELLO, WORLD!

</script>

</head>

<body>

<h1>JavaScript Built-in Objects</h1>

</body>

</html>

<?php

// Creating Variables

$name = "John";

$age = 25;

$height = 1.75;

// Creating Constants

define("PI", 3.14159);

define("GREETING", "Hello, World!");

echo $name; // Output: John

echo $age; // Output: 25

echo $height; // Output: 1.75

echo PI; // Output: 3.14159

echo GREETING; // Output: Hello, World!


?>

<?php

// For Loop

for ($i = 0; $i < 10; $i++) {

echo $i . " ";

// While Loop

$i = 0;

while ($i < 10) {

echo $i . " ";

$i++;

// Do-While Loop

$i = 0;

do {

echo $i . " ";

$i++;

} while ($i < 10);

// Foreach Loop

$colors = array("Red", "Green", "Blue");

foreach ($colors as $color) {


echo $color . " ";

?>

<?php

// Setting a cookie

setcookie("name", "John", time() + (86400 * 30), "/"); // expires in 30 days

// Retrieving a cookie

echo $_COOKIE["name"]; // Output: John

// Deleting a cookie

setcookie("name", "", time() - 3600); // expires in 1 hour ago

?>

You might also like