Professional Documents
Culture Documents
Develop Any Javascript To Implement Functions.
Develop Any Javascript To Implement Functions.
<!DOCTYPE HTML>
<html>
<head>
<title>Function Demo</title>
<script type="text/javascript">
function my_fun()
{
document.write("This statement is within the function");
}
</script>
</strong>
<body>
<center>
<script type="text/javascript">
document.write("This statement is before a function call ");
document.write("<br>");
my_fun();
</script>
</center>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Call JavaScript from HTML</title>
<script>
// Define a JavaScript function
function greet() {
alert("Hello, world!");
}
</script>
</head>
<body>
<!-- Call the JavaScript function when the button is clicked -->
<button onclick="greet()">Click me to greet</button>
</body>
</html>
3. Write a JavaScript function that checks wether a passed string is palindrom or not.
<script>
function isPalindrome(str) {
// Remove non-alphanumeric characters and convert to lowercase
str = str.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
document.write(isPalindrome("racecar")); // true
document.write(isPalindrome("hello")); // false
document.write(isPalindrome("A man, a plan, a canal, Panama")); // true
</script>
4. Write JavaScript function to generate Fibonacci Series till user defind limit.
<script>
function generateFibonacciSeries(limit) {
if (limit <= 0) {
return [];
} else if (limit === 1) {
return [0];
}
return series;
}
</script>