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

JavaScript Programs for Beginners

The document provides various simple JavaScript programs designed for beginners, including examples for generating Fibonacci sequences, form validation, palindrome checking, and determining odd/even numbers. Each program is structured with HTML and JavaScript code snippets, demonstrating basic functionalities such as user input handling and conditional statements. Additionally, it includes a switch case example for displaying the days of the week based on user input.

Uploaded by

BTCST
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)
6 views2 pages

JavaScript Programs for Beginners

The document provides various simple JavaScript programs designed for beginners, including examples for generating Fibonacci sequences, form validation, palindrome checking, and determining odd/even numbers. Each program is structured with HTML and JavaScript code snippets, demonstrating basic functionalities such as user input handling and conditional statements. Additionally, it includes a switch case example for displaying the days of the week based on user input.

Uploaded by

BTCST
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

JavaScript Programs with Examples else

Fibonacci Series JavaScript Program (for beginners) alert("Form has been submitted");
This is a simple JavaScript example program for fibonacci }
sequence. </script>
</head>
<html> <body>
<body> <form>
<script type="text/javascript"> <p align="center">
var a=0,b=1,c; User Name:<input type="text" id="t1"><br><br>
[Link]("Fibonacci"); Password:<input type="text" id="t2"><br><br>
while (b<=10) Confirm Password:<input type="text" id="t3"><br><br>
{ Address:<textarea rows="2" cols="25"
[Link](c); id="t4"></textarea><br><br>
[Link]("<br/>"); <input type="button" value="Submit" onclick="sub()">
c=a+b; <input type="reset" value="Clear All">
a=b; </p>
b=c; </form>
} </body>
</script> </html>
</body>
</html> JavaScript Popup Window Program (for beginners)
This is a simple JavaScript example program to generate
Copy Text JavaScript Program (for beginners) confirm box.
This is simple JavaScript Program with example to Copy
Text from Different Field. <html>
<head>
<html> <script type="text/javaScript">
<head> function see()
<title> {
Copy text</title> var c= confirm("Click OK to see Google Homepage or
</head> CANCEL to see Bing Homepage");
<body> if (c== true)
<center> {
<h2>Copy text from different field</h2> [Link]="[Link]
<p> }
<input type="text" style="color: #FF0080;background- else
color: #C9C299" id="field1" value="Good Morning"> {
<input type="text" style="color: #FF0080;background- [Link]="[Link]
color: #C9C299" id="field2"> }
<button style="background-color: #E799A3" }
onclick="[Link]('field2').value = </script>
[Link]('field1').value">Click to Copy </head>
Text <body>
</p> <center>
</center> <form>
</body> <input type="button" value="Click to chose either Google
</html> or Bing" onclick="see()">
</form>
Form Validation JavaScript Program (for beginners) </center>
This is a simple JavaScript form validation program with </body>
example. </html>

<html>
<head> Palindrome JavaScript Program (for beginners)
<script type="text/javascript"> This is a simple JavaScript palindrome program with
function sub() example.
{
if([Link]("t1").value == "")
alert("Please enter your name"); <html>
else if([Link]("t2").value == "") <body>
alert("Please enter a password"); <script type="text/javascript">
else if([Link]("t2").value != function Palindrome() {
[Link]("t3").value) var revStr = "";
alert("Please enter correct password"); var str = [Link]("str").value;
else if([Link]("t4").value == "") var i = [Link];
alert("Please enter your address"); for(var j=i; j>=0; j--) {
revStr = revStr+[Link](j); break;
} case (n="2"):
if(str == revStr) { [Link]("Monday");
alert(str+" -is Palindrome"); break;
} else { case (n="3"):
alert(str+" -is not a Palindrome"); [Link]("Tuesday");
} break;
} case (n="4"):
</script> [Link]("Wednesday");
<form > break;
Enter a String/Number: <input type="text" id="str" case (n="5"):
name="string" /><br /> [Link]("Thursday");
<input type="submit" value="Check" break;
onclick="Palindrome();"/> case (n="6"):
</form> [Link]("Friday");
</body> break;
</html> case (n="7"):
[Link]("Saturday");
break;
Check Odd/Even Numbers JavaScript Program (for default:
beginners) [Link]("Invalid Weekday");
This is a simple JavaScript program to check odd or even break
numbers with example. }
</script>
</head>
<html> </html>
<head>
<script type="text/javascript"> FIND MAXIMUM
var n = prompt("Enter a number to find odd or even", "Type <script>
your number here"); var max = 0
n = parseInt(n); var num
if (isNaN(n)) num = prompt("Enter new value, or 0
{ to end")
alert("Please Enter a Number"); while (num != 0) {
} if (parseFloat(num) > max)
else if (n == 0) max = num
{ num = prompt("Enter new value,
alert("The number is zero"); or 0 to end")
} }
else if (n%2) [Link]("<P> Max = " + max)
{ </script>
alert("The number is odd");
}
else
{
alert("The number is even");
}
</script>
</head>
<body>
</body>
</html>

Simple Switch Case JavaScript Program (for beginners)


This is a simple switch case JavaScript example program for
beginners..

<html>
<head>
<script type="text/javascript">
var n=prompt("Enter a number between 1 and 7");
switch (n)
{
case (n="1"):
[Link]("Sunday");

You might also like