0% found this document useful (0 votes)
1 views

Shivam js lab 1

The document contains a series of JavaScript code snippets designed for a lab sheet, covering various programming tasks such as arithmetic operations, area and perimeter calculations, temperature conversions, and conditional statements. Each snippet prompts the user for input and displays the results directly on the webpage. The exercises range from basic calculations to more complex logic involving conditions and loops.

Uploaded by

presentera16
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Shivam js lab 1

The document contains a series of JavaScript code snippets designed for a lab sheet, covering various programming tasks such as arithmetic operations, area and perimeter calculations, temperature conversions, and conditional statements. Each snippet prompts the user for input and displays the results directly on the webpage. The exercises range from basic calculations to more complex logic involving conditions and loops.

Uploaded by

presentera16
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

JavaScript Labsheet 1

1.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let num1 = parseInt(prompt("Enter first number"));

let num2 = parseInt(prompt("Enter second number"));

document.write(`Sum: ${num1 + num2} `);

document.write(`Difference: ${num1 - num2} `);

document.write(`Product: ${num1 * num2} `);

document.write(`Division: ${num1 / num2} `);

</script>

</head>

<body>

</body>

</htm

l>
2.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let length = parseInt(prompt("Enter length"));

document.write(`Length: ${length} `);

document.write(`Area of cube: ${6 * length * length} sqcm`);

</script>

</head>

<body>

</body>

</html>
3.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

const pi = 3.14;

let radius = parseInt(prompt("Enter radius"));

document.write(`Radius: ${radius} `);

document.write(`Area of circle: ${pi * radius * radius} sqcm `);

document.write(`Circumference: ${2 * pi * radius} cm`);

</script>

</head>

<body>

</body>

</html>
4.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let length = parseInt(prompt("Enter length"));

let breadth = parseInt(prompt("Enter breadth"));

document.write(`Length: ${length} Breadth: ${breadth} `);

document.write(`Area: ${length * breadth} sqcm `);

document.write(`Perimeter: ${2 * (length + breadth)} cm`);

</script>

</head>

<body>

</body>

</html>
5.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let num1 = parseInt(prompt("Enter first number"));

let num2 = parseInt(prompt("Enter second number"));

document.write(`Quotient: ${Math.floor(num1 / num2)} `);

document.write(`Remainder: ${num1 % num2}`);

</script>

</head>

<body>

</body>

</html>
6.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let totalSeconds = parseInt(prompt("Enter total seconds"));

let hours = Math.floor(totalSeconds / 3600);

let minutes = Math.floor((totalSeconds % 3600) / 60);

let seconds = totalSeconds % 60;

document.write(`${hours} hours, ${minutes} minutes, ${seconds} seconds`);

</script>

</head>

<body>

</body>

</html>
7.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let totalDays = parseInt(prompt("Enter total days"));

let years = Math.floor(totalDays / 365);

let months = Math.floor((totalDays % 365) / 30);

let days = totalDays % 365;

document.write(`${years} years, ${months} months, ${days} days`);

</script>

</head>

<body>

</body>

</html>
8.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let number = parseInt(prompt("Enter a two-digit number"));

let reversed = (number % 10) * 10 + Math.floor(number / 10);

document.write(`Original: ${number}, Reversed: ${reversed}`);

</script>

</head>

<body>

</body>

</html>
9.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let celsius = parseFloat(prompt("Enter temperature in Celsius"));

let fahrenheit = (9 * celsius) / 5 + 32;

document.write(`Celsius: ${celsius}, Fahrenheit: ${fahrenheit}`);

</script>

</head>

<body>

</body>

</html>
10.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let a = parseFloat(prompt("Enter coefficient a"));

let b = parseFloat(prompt("Enter coefficient b"));

let c = parseFloat(prompt("Enter coefficient c"));

let discriminant = b * b - 4 * a * c;

if (discriminant > 0) {

let root1 = (-b + Math.sqrt(discriminant)) / (2 * a);

let root2 = (-b - Math.sqrt(discriminant)) / (2 * a);

document.write(`Roots: ${root1}, ${root2}`);

} else if (discriminant == 0) {

let root = -b / (2 * a);

document.write(`Root: ${root}`);

} else {

let realPart = -b / (2 * a);

let imaginaryPart = Math.sqrt(-discriminant) / (2 * a);

document.write(`Roots: ${realPart} + ${imaginaryPart}i, ${realPart} - $


{imaginaryPart}i`);

}
</script>

</head>

<body>

</body>

</html>
11.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let a = parseInt(prompt("Enter a number:"));

if (a % 2 == 0) {

document.write(`${a} is even`);

} else {

document.write(`${a} is odd`);

</script>

</head>

<body>

</body>

</html>
12.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

document.write(`Qn.12 `);

let a = parseInt(prompt("enter first number:"));

let b = parseInt(prompt("enter second number:"));

let c = parseInt(prompt("enter third number:"));

if (a > b && a > c){

document.write(`${a} is largest`);

else if (b > c && b > c){

document.write(`${b} is largest`);

else if (c > a && c > b){

document.write(`${c} is largest`);

</script>

</head>

<body>
</body>

</html>
13.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let a = parseInt(prompt("enter first number:"));

let b = parseInt(prompt("enter second number:"));

let c = parseInt(prompt("enter third number:"));

if (a < b && a < c){

document.write(`${a} is smallest`);

else if (b < c && b < c){

document.write(`${b} is smallest`);

else if (c < a && c < b){

document.write(`${c} is smallest`);

</script>

</head>

<body>

</body>

</html>
14..

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let commission;

let sales = parseInt(prompt("enter total amount of sales: "));

if(sales <= 5000){

commission = sales * 0.01;

document.write(`commission amount is : RS. ${commission}`);

else if(sales > 5000 && sales <= 8000 ){

commission = sales * 0.03;

document.write(`commission amount is : RS. ${commission}`);

else if(sales >8000 && sales >=11000){

commission = sales * 0.05;

document.write(`commission amount is : RS. ${commission}`);

else if(sales > 11000){

commission = sales * 0.1;


document.write(`commission amount is : RS. ${commission}`);

</script>

</head>

<body>

</body>

</html>
15.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

const heater = 1500;

const toaster = 200;

const fan = 400;

let n = parseInt(prompt("enter no of heaters:"));

let m = parseInt(prompt("enter no of toasters:"));

let p = parseInt(prompt("enter no of fans:"));

let heater_price = n * heater;

let toaster_price = m*toaster;

let fan_price = p*fan;

let after_dis_heater = heater_price - (0.05 * heater_price);

let after_dis_toaster= toaster_price - (0.1 * toaster_price);

let after_dis_fan = fan_price - (0.15 * fan_price);

let total = (after_dis_fan + after_dis_heater + after_dis_toaster) + 0.1*(after_dis_fan


+ after_dis_heater + after_dis_toaster);

document.write(` total amt to be paid is : ${total}`);

</script>

</head>

<body>
</body> </html>

16 & 17.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let cp = parseInt(prompt("Enter cost price:"));

let sp = parseInt(prompt("Enter selling price:"));

if (sp > cp) {

let profit = sp - cp;

document.write(`Profit: Rs. ${profit}`);

} else {

let loss = cp - sp;

document.write(`Loss: Rs. ${loss}`);

</script>

</head>

<body>

</body> </html>
18.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let length = parseInt(prompt("Enter length:"));

let breadth = parseInt(prompt("Enter breadth:"));

let area = length * breadth;

let perimeter = 2 * (length + breadth);

if (area > perimeter) {

document.write(`Area is greater than perimeter.`);

} else {

document.write(`Perimeter is greater than area.`);

</script>

</head>

<body>

</body> </html>
19.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let a = parseInt(prompt("enter first num: "));

let b = parseInt(prompt("enter second num: "));

let greatest = (a>b)? `${a} is greatest` : `${b} is greatest `;

document.write(greatest);

</script>

</head>

<body>

</body> </html>
20.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let year = parseInt(prompt("enter the year: "));

if((year % 100 == 0 && year % 400 == 0) || (year % 4 == 0)){

document.write(`${year} is leap year.`);

else{

document.write(`${year} is not leap year.`);

</script>

</head>

<body>

</body> </html>
21.

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let ascii = parseInt(prompt("enter ascii value: "));

document.write(`ascii value ${ascii} `);

if (ascii >= 65 && ascii <= 90) {

document.write("The character is a capital letter.");

} else if (ascii >= 97 && ascii <= 122) {

document.write("The character is a small letter.");

} else if (ascii >= 48 && ascii <= 57) {

document.write("The character is a digit.");

} else if (

(ascii >= 0 && ascii <= 47) ||

(ascii >= 58 && ascii <= 64) ||

(ascii >= 91 && ascii <= 96) ||

(ascii >= 123 && ascii <= 127))

document.write("The character is a special symbol.");

else {

document.write("The character is not a valid ASCII character.");


}

</script>

</head>

<body>

</body> </html>

22.

<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Js lab 1</title>

<script>

let num = parseInt(prompt("enter a number:"));

let count = 0;

if(num == 1 ){

document.write("not prime: ");

for(let i=1; i<=num ;i++){

if(num % i ==0){

count++;

if( count == 2){

document.write(`${num} is prime`);

else{

document.write(`${num} is not prime`);

</script>

</head>

<body>

</body> </html>

You might also like