JavaScript Assignments
JavaScript Assignments
Alert
1. Write a script to greet your website visitor using JS alert box.
2. Write a script to display following message on your web page:
(Hint : Use line break \n )
2. Declare a variable called book & give it the value “A smarter way to learn
JavaScript”. Display this in browser through JS.
(Hint: use document.write())
var a = 2, b = 1;
var result = --a - --b + ++b + b--;
Conversion Formulae:
Prompts
1. Take user name form user on prompt and greet user by his name on
the alert box.
if statements
1. Write a program to take “gender” as input from user. If the user is
male, give the message: Good Morning Sir. If the user is female, give
the message: Good Morning Ma’am.
Comparison Operators
1. Write a program that takes input a number from user
& state whether the number is positive, negative or
zero.
2. Write a program that
a. Store correct password in a JS variable.
b. Asks user to enter his/her password
c. Validate the two passwords:
i. Check if user has entered password. If not, then
give message “ Please enter your password”
ii. Check if both passwords are same. If they are
same, show message “Correct! The password
you entered matches the original password”.
Show “Incorrect password” otherwise.
Arrays
1. Write a program to store 3 student names in an array.Take
another array to store score of these three students.
Assume that total marks are 500 for each student, display
the scores & percentages of students like.
for loops
3. Write a program that prints fruits name from start of the array to
desired stop value. Given array:
var fruits = [apple, orange, banana, graps, mango];
(Hint: take stop value from user)
E.g. if user gives 3 as input value print apple, orange, banana.
Challenge
Note: Challenge is not included in Assignments.
1. Write a program that will write out a wedge of stars. The user will
enter the initial number of stars, and the program will write out lines of
stars where each line has one few star than the previous line. Initial
number of stars: 7
Output:
*******
******
*****
****
***
**
*
c.
*****
****
***
**
*
d.
*
**
***
****
*****
******
*******
********
*********
**********
***********
**********
*********
********
*******
******
*****
****
***
**
*