Javascript Program
Javascript Program
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<script>
function calculateSum() {
// Get the input values
var num1 = parseInt(document.getElementById('num1').value);
var num2 = parseInt(document.getElementById('num2').value);
function addNumbers(a, b) {
return a + b;
}
</script>
<h2>Sum Calculator</h2>
<form id="sumForm">
<label for="num1">Enter first number:</label>
<input type="number" id="num1" name="num1" required><br><br>
<div id="result"></div>
<script src="script.js"></script>
</body>
</html>
============================================SECOND EXAMPLE:
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<script>
function calculateSum() {
// Get the input array values
var inputArray = document.getElementById('arrayValues').value;
function sumArray(arr) {
var sum = 0;
for (var i = 0; i < arr.length; i++) {
sum += arr[i];
}
return sum;
}
</script>
<div id="result"></div>
<script src="script.js"></script>
</body>
</html>
===========================================
same as before regarding your 1st activities (please your answer in the gdrive) -
program and output must be present in the MSWORD.
[email protected] - invite me as editor. thanks po
1. Sum of Array Elements: Write a function that takes an array of numbers as input
and returns the sum of all the elements.
2. Reverse String: Write a function that takes a string as input and returns the
reverse of that string.
3. Find Maximum Number: Write a function that takes an array of numbers as input
and returns the maximum number in the array.
4. Factorial: Write a function that calculates the factorial of a given number
using recursion.
5. Check Prime Number: Write a function that checks whether a given number is prime
or not.
6. Generate Random Number: Use the Math.random() method to generate a random number
between a specified range.
7. Count Vowels in a String: Write a function that counts the number of vowels in a
given string.
8. Convert Celsius to Fahrenheit: Write a function that converts temperature from
Celsius to Fahrenheit.
9. Get Current Date and Time: Use the Date object to get the current date and time.
10. Calculate Age: Write a function that calculates the age of a person based on
their birthdate.