0% found this document useful (0 votes)
13 views2 pages

JavaScript Lab Manual for Students

The document is a JavaScript lab manual authored by Dr. D. K. Meena, containing various programming exercises including computing the sum of an array, checking leap years, and validating mobile numbers. It provides a detailed example of a program that calculates the sum of an array of integers, including the HTML and JavaScript code used. Additionally, it includes VBScript exercises for tasks like Fibonacci sequence generation and age validation.

Uploaded by

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

JavaScript Lab Manual for Students

The document is a JavaScript lab manual authored by Dr. D. K. Meena, containing various programming exercises including computing the sum of an array, checking leap years, and validating mobile numbers. It provides a detailed example of a program that calculates the sum of an array of integers, including the HTML and JavaScript code used. Additionally, it includes VBScript exercises for tasks like Fibonacci sequence generation and age validation.

Uploaded by

Sanya Dixit
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Dr D. K.

Meena Assistant Professor Computer Science Department


Kalindi Collage University of Delhi
Java Script Lab manual
1. Write a JavaScript program to compute the sum of an array of
integers
2. Write a JavaScript program to determine whether a given year is a
leap year in theGregorian calendar
3. Write a JavaScript for loop that will iterate from 0 to 15. For each
iteration, it will check ifthe current number is odd or even, and
display a message to the screen
4. Write a JavaScript program to calculate multiplication and division of
two numbers
5. Write a JavaScript program to convert temperatures to and from
Celsius, Fahrenheit
6. Write a JavaScript function that reverses a number
7. Write a JavaScript function that checks whether a passed string is
palindrome or not
8. Write a JavaScript program to test the first character of a string is
uppercase or not
9. Write a JavaScript program to set the background colour of a
paragraph
10. Write a JavaScript program to check the given number is mobile
number or not usingform
11. Write a VBScript program for Fibonacci using for loop
12. Write a VBScript Program for age validation
13. Write a VBScript program to Copy contents of one folder to other
folder
14. Write a VBScript program to demonstrate the checkbox and list
box
Experiment-1
Aim:
To write a program to compute the sum of an array of integers using
javascript.
Procedure:
 Start the execution of the program
 Create the array with 6 elements
 Calculate the sum of array of integers using for loop
 Print the value of sum
 Stop the execution of the program
Coding
<html>
<head>
<title>Compute the sum of an array of integers</title>
<script>
var array = [1, 2, 3, 4, 5, 6], s = 0, i;
for (i = 0; i < [Link]; i += 1)
s += array[i];
[Link]("Sum of array of Integers: "+s);
</script>
</head>
<body></body>
</html>

Result: Result: Sum of array of Integers: 21

Common questions

Powered by AI

Implementing mobile number validation in JavaScript typically involves using a regular expression pattern to check the string against expected formats. Considerations include international formats, required length, and allowed characters (e.g., only digits or dashes).

JavaScript manipulates dynamic content like a paragraph's background color through the Document Object Model (DOM) using methods such as getElementById or querySelector paired with style properties. This approach is effective due to its direct interaction with web page elements, allowing real-time updates and user interaction .

Writing a JavaScript function to check for palindromes involves converting the string to lowercase, removing non-alphanumeric characters, and comparing the string to its reverse. Edge cases include handling empty strings, single character strings, and variations in casing and punctuation .

The algorithm to calculate the sum of an array of integers in JavaScript involves initializing a sum variable to zero, then iterating through each element of the array using a for loop. For each iteration, the current array element is added to the sum variable. This process continues until all array elements have been processed. Key considerations include ensuring that the array is properly defined and initialized, and that the loop correctly traverses the entire array .

To determine if a year is a leap year in JavaScript, you check the following criteria: a year is a leap year if it is divisible by 4 but not divisible by 100, unless it is also divisible by 400. The logic uses conditional statements to check divisibility, allowing determination based on the Gregorian calendar rules .

A JavaScript algorithm to reverse a number involves converting the number to a string, splitting the string into an array of characters, reversing the array, and then joining the array back into a string before converting it back to a number. Challenges may arise with handling negative numbers, preserving the sign, and avoiding loss of precision with large numbers .

The program uses a for loop to iterate through a range of numbers. Within each iteration, the modulo operator (%) determines if the current number is odd or even by checking the remainder when divided by 2. Differentiating between odd and even numbers is fundamental in programming as it helps in control flow and logic-based operations .

JavaScript can convert temperatures by implementing the formulas: °F = °C × 9/5 + 32 and °C = (°F - 32) × 5/9. The mathematical basis for this conversion lies in the relationship between the Celsius and Fahrenheit scales, where 0°C is 32°F and 100°C is 212°F, establishing a linear transformation between them .

VBScript has native file system manipulation capabilities through the FileSystemObject, allowing direct file copying, whereas JavaScript in the browser environment lacks file system access for security reasons. Complexities in VBScript include error handling and ensuring correct file paths. These can be addressed by implementing robust error-capture logic and validating paths before operations .

JavaScript methods such as charAt(0) and a regex pattern like /^[A-Z]/ can check if the first character is uppercase. Scenarios complicating this check include strings that start with non-letter characters, whitespace, or are empty, which require additional handling .

You might also like