Write a script to greet your website visitor using JS alert box.
Write a script to display following message on your web page:
Write a script to display following message on your web page: (Hint : Use line break)
Write a script to display following messages in sequence:
Generate the following message through browser’s developer console:
Make use of alerts in your new/existing HTML & CSS project.
Practice placement of
script element in following sections of your project in exercise 6:
a. Head
b. Body (before your page’s HTML)
c. Body (inside your page’s HTML)
d. Body (after your page’s HTML)
Declare a variable called username.
Declare a variable called myName & assign to it a string that represents your Full Name.
Write script to
a) Declare a JS variable, titled message.
b) Assign “Hello World” to variable message
c) Display the message in alert box.
Write a script to save student’s bio data in JS variables and show the data in alert boxes.:
Write a script to display the following alert using one JS variable:
Declare a variable called email and assign to it a string that represents your Email Address(e.g. example@example.com). Show the blow mentioned message in an alert box.(Hint: use string concatenation)
Declare a variable called book & give it the value “A smarter way to learn JavaScript”. Display the following message in an alert box:
Write a script to display this in browser through JS
Store following string in a variable and show in alert and browser through JS
Declare a variable called age & assign to it your age. Show your age in an alert box.
Declare & initialize a variable to keep track of how many times a visitor has visited a web page. Show his/her number of visits on your web page. For example: “You have visited this site N times”.
Declare a variable called birthYear & assign to it your birth year. Show the following message in your browser:
A visitor visits an online clothing store
www.xyzClothing.com . Write a script to store in variables
the following information:
a. Visitor’s name
b. Product title
c. Quantity i.e.
how many products a visitor wants to
order Show the following message in your browser: “John
Doe ordered 5 T-shirt(s) on XYZ Clothing store”.
Declare 3 variables in one statement.
Declare 5 legal & 5 illegal variable names.
Display this in your browser
a) A heading stating “Rules for naming JS variables”
b) Variable names can only contain ______, ______,
______ and ______.
For example $my_1stVariable
c) Variables must begin with a ______, ______ or
_____.
For example $name, _name or name
d) Variable names are case _________
e) Variable names should not be JS _________
Write a program that take two numbers & add them in a new variable. Show the result in your browser.
Repeat task1 for subtraction, multiplication, division & modulus.
Do the following using JS Mathematic Expressions
a. Declare a variable.
b. Show the value of variable in your browser like “Value
after variable declaration is: ??”.
c. Initialize the variable with some number.
d. Show the value of variable in your browser like “Initial
value: 5”.
e. Increment the variable.
f. Show the value of variable in your browser like “Value
after increment is: 6”.
g. Add 7 to the variable.
h. Show the value of variable in your browser like “Value
after addition is: 13”.
i. Decrement the variable.
j. Show the value of variable in your browser like “Value
after decrement is: 12”.
k. Show the remainder after dividing the variable’s value
by 3.
l. Output : “The remainder is : 0”.
Cost of one movie ticket is 600 PKR. Write a script to store ticket price in a variable & calculate the cost of buying 5 tickets to a movie. Example output:
Write a script to display multiplication table of any number in your browser. E.g
The Temperature Converter: It’s hot out! Let’s make a
converter based on the steps here.
a. Store a Celsius temperature into a variable.
b. Convert it to Fahrenheit & output “NNoC is NNoF”.
c. Now store a Fahrenheit temperature into a variable.
d. Convert it to Celsius & output “NNoF is NNoC”.
Write a program to implement checkout process of a
shopping cart system for an e-commerce website. Store
the following in variables
a. Price of item 1
b. Price of item 2
c. Ordered quantity of item 1
d. Ordered Quantity of item 2
e. Shipping charges
Compute the total cost & show the receipt in your browser.
Store total marks & marks obtained by a student in 2 variables. Compute the percentage & show the result in your browser
Assume we have 10 US dollars & 25 Saudi Riyals. Write a script to convert the total currency to Pakistani Rupees. Perform all calculations in a single expression. (Exchange rates : 1 US Dollar = 104.80 Pakistani Rupee and 1 Saudi Riyal = 28 Pakistani Rupee)
Write a program to initialize a variable with some
number and do arithmetic in following sequence:
a. Add 5
b. Multiply by 10
c. Divide the result by 2
Perform all calculations in a single expression
The Age Calculator: Forgot how old someone is?
Calculate it!
a. Store the current year in a variable.
b. Store their birth year in a variable.
c. Calculate their 2 possible ages based on the stored
values.
The Geometrizer: Calculate properties of a circle.
a. Store a radius into a variable.
b. Calculate the circumference based on the radius, and
output “The circumference is NN”.
(Hint : Circumference of a circle = 2 π r , π = 3.142)
Calculate the area based on the radius, and output “The
area is NN”. (Hint : Area of a circle = π r2, π = 3.142)
The Lifetime Supply Calculator: Ever wonder how
much a “lifetime supply” of your favorite snack is?
Wonder no more.
a. Store your favorite snack into a variable
b. Store your current age into a variable.
c. Store a maximum age into a variable.
d. Store an estimated amount per day (as a number).
e. Calculate how many would you eat total for the rest of
your life.
Output the result to the screen like so: “You will need
NNNN to last you until the ripe old age of NN”.
Write a program to take a number in a variable, do the required arithmetic to display the following result in your browser:
What will be the output in variables a, b & result after
execution of the following script:
var a = 2, b = 1;
var result = --a - --b + ++b + b--;
Explain the output at each stage:
--a;
--a - --b;
--a - --b + ++b;
--a - --b + ++b + b--;
Write a program that takes input a name from user & greet the user.
Write a program to take input a number from user & display it’s multiplication table on your browser. If user does not enter a new number, multiplication table of 5 should be displayed by default.
Take
a) Take three subjects name from user and store them in 3
different variables.
b) Total marks for each subject is 100, store it in another
variable.
c) Take obtained marks for first subject from user and
stored it in different variable.
d) Take obtained marks for remaining 2 subjects from user
and store them in variables.
e) Now calculate total marks and percentage and show the
result in browser like this.(Hint: user table)
Write a program to take “city” name as input from user. If user enters “Karachi”, welcome the user like this: “Welcome to city of lights”
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.
Write a program to take input color of road traffic signal from the user & show the message according to this table:
Write a program to take input remaining fuel in car (in litres) from user. If the current fuel is less than 0.25litres, show the message “Please refill the fuel in your car”
Run this script, & check whether alert message would be
displayed or not. Record the outputs.
var a = 4;
if (++a === 5){
alert("given condition for variable a is true");
}
var b = 82;
if (b++ === 83){
alert("given condition for variable b is true");
}
var c = 12;
if (c++ === 13){
alert("condition 1 is true");
}
if (c === 13){
alert("condition 2 is true");
}
if (++c < 14){
alert("condition 3 is true");
}
if(c === 14){
alert("condition 4 is true");
}
var materialCost = 20000;
var laborCost = 2000;
var totalCost = materialCost + laborCost;
if (totalCost === laborCost + materialCost){
alert("The cost equals");
}
if (true){
alert("True");
}
if (false){
alert("False");
}
if("car" < "cat"){
alert("car is smaller than cat");
}
Write a program to take input the marks obtained in three subjects & total marks. Compute & show the resulting percentage on your page. Take percentage & compute grade as per following table:
Write a program to check whether the given number is divisible by 3. Show the message to the user if the number is divisible by 3.
Write a program that checks whether the given input is an even number or an odd number.
Write a program that takes temperature as input and shows a message based on following criteria
a. T > 40 then “It is too hot outside.”
b. T > 30 then “The Weather today is Normal.”
c. T > 20 then “Today’s Weather is cool.”
d. T > 10 then “OMG! Today’s weather is so Cool.”.
Write a program to create a calculator for +,-,*, / & % using if statements.
Take the following input:
a. First number
b. Second number
c. Operation (+, -, *, /,
%)
Compute & show the calculated
result to user.
Write a program that takes a character (number or string) in a variable & checks whether the given input is a number, uppercase letter or lower case letter. (Hint: ASCII codes:- A=65, Z=90, a=97, z=122).
Write a JavaScript program that accept two integers and display the larger. Also show if the two integers are equal.
Write a program that takes input a number from user & state whether the number is positive, negative or zero.
Write a program that takes a character (i.e. string of length 1) and returns true if it is a vowel, false otherwise
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.
This if/else statement does not work.
Try to fix it:
var greeting;
var hour = 13;
if (hour < 18)
{
greeting="Good day" ;
}
else greeting="Good evening" ;
}
Write a program that takes time as input from user in 24 hours clock format like: 1900 = 7pm. Implement the following case using if, else & else if statements
Declare an empty array using JS literal notation to store student names in future
Declare an empty array using JS object notation to store student names in future.
Declare and initialize a strings array.
Declare and initialize a Number array.
Declare and initialize a boolean array.
Declare and initialize a mixed array.
Declare and Initialize an array and store available education qualifications in Pakistan (e.g. SSC, HSC, BCS, BS, BCOM, MS, M. Phil., PhD). Show the listed qualifications in your browser like
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:
Initialize an array with color names. Display the array elements in your browser.
a. Ask the user what color he/she wants to add to the beginning & add that color to the beginning of the array. Display the updated array in your browser.
b. Ask the user what color he/she wants to add to the end & add that color to the end of the array. Display the updated array in your browser.
c. Add two more color to the beginning of the array. Display the updated array in your browser.
d. Delete the first color in the array. Display the updated array in your browser.
e. Delete the last color in the array. Display the updated array in your browser.
f. Ask the user at which index he/she wants to add a color & color name. Then add the color to desired position/index. . Display the updated array in your browser.
g. Ask the user at which index he/she wants to delete color(s) & how many colors he/she wants to delete. Then remove the same number of color(s) from user-defined position/index. . Display the updated array in your browser.
Write a program to store student scores in an array & sort the array in ascending order using Array’s sort method.
Write a program to initialize an array with city names. Copy 3 array elements from cities array to selectedCities array.
Write a program to create a single string from the below mentioned array: var arr = [“This ”, “ is ”, “ my ”, “ cat”]; (Use array’s join method)
Create a new array. Store values one by one in such a way that you can access the values in the order in which they were stored. (FIFO-First In First Out)
Create a new array. Store values one by one in such a way that you can access the values in reverse order. (Last In First Out
Write a program to store phone manufacturers (Apple, Samsung, Motorola, Nokia, Sony & Haier) in an array. Display the following dropdown/select menu in your browser using document.write() method.
Declare and initialize an empty multidimensional array. (Array of arrays)
Declare and initialize a multidimensional array representing the following matrix:
Write a program to print numeric counting from 1 to 10..
Write a program to print multiplication table of any number using for loop. Table number & length should be taken as an input from user.
Write a program to print items of the following array using for loop: fruits = [“apple”, “banana”, “mango”, “orange”, “strawberry”]
Generate the following series in your browser. See example output.
a. Counting: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
b. Reverse counting: 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
c. Even: 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20
d. Odd: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19
e. Series: 2k, 4k, 6k, 8k, 10k, 12k, 14k, 16k, 18k, 20k
You have an array
A = [“cake”, “apple pie”, “cookie”, “chips”, “patties”]
Write a program to enable “search by user input” in an
array.
After searching, prompt the user whether the given item is
found in the list or not. Example:
Write a program to identify the largest number in the
given array.
A = [24, 53, 78, 91, 12]
Write a program to identify the small number in the
given array.
A = [24, 53, 78, 91, 12]
Write a program to print multiples of 5 ranging 1 to 100.
Write a program that takes two user inputs for first and last name using prompt and merge them in a new variable titled fullName. Greet the user using his full name.
Write a program to take a user input about his favorite mobile phone model. Find and display the length of user input in your browser
Write a program to find the index of letter “n” in the word “Pakistani” and display the result in your browser .
Write a program to find the last index of letter “l” in the word “Hello World” and display the result in your browser.
Write a program to find the character at 3rd index in the word “Pakistani” and display the result in your browser.
Repeat Q1 using string concat() method.
Write a program to replace the “Hyder” to “Islam” in the word “Hyderabad” and display the result in your browser.
>Write a program to replace all occurrences of “and” in the string with “&” and display the result in your browser. var message = “Ali and Sami are best friends. They play cricket and football together.”;
Write a program that converts a string “472” to a number 472. Display the values & types in your browser.
Write a program that takes user input. Convert and show the input in capital letters.
Write a program that takes user input. Convert and show the input in title case.
Write a program that converts the variable num to string.
Write a program to take user input and store username in a variable. If the username contains any special symbol among [@ . , !], prompt the user to enter a valid username. For character codes of [@ .
You have an array
A = [“cake”, “apple pie”, “cookie”, “chips”, “patties”]
Write a program to enable “search by user input” in an
array.
After searching, prompt the user whether the given item is
found in the list or not. Example:
Note: Perform case insensitive search. Whether the user
enters cookie, Cookie, COOKIE or coOkIE, program
should inform about its availability. Example:
Write a program to take password as an input from
user. The password must qualify these requirements:
a. It should contain alphabets and numbers
b. It should not start with a number
c. It must at least 6 characters long
If the password does not meet above requirements,
prompt the user to enter a valid password.
For character codes of a-z, A-Z & 0-9, refer to ASCII
table at the end of this document.
Write a program to convert the following string to an array using string split method. var university = “University of Karachi”; Display the elements of array in your browser.
Write a program to display the last character of a user input.
You have a string “The quick brown fox jumps over the lazy dog”. Write a program to count number of occurrences of word “the” in given string.
Write a program that takes a positive integer from user &
display the following in your browser.
a. number
b. round off value of the number
c. floor value of the number
d. ceil value of the number
Write a program that takes a negative floating point
number from user & display the following in your browser.
a. number
b. round off value of the number
c. floor value of the number
d. ceil value of the number
Write a program that displays the absolute value of a
number.
E.g. absolute value of -4 is 4 & absolute value of 5 is 5
Write a program that simulates a dice using random() method of JS Math class. Display the value of dice in your browser.:
Write a program that simulates a coin toss using random() method of JS Math class. Display the value of coin in your browser
Write a program that shows a random number between 1 and 100 in your browser.
Write a program that asks the user about his weight. Parse
the user input and display his weight in your browser.
Possible user inputs can be:
a. 50
b. 50kgs
c. 50.2kgs
d. 50.2kilograms
Write a program that stores a random secret number from 1 to 10 in a variable. Ask the user to input a number between 1 and 10. If the user input equals the secret number, congratulate the user.
Write a program that displays current date and time in your browser.
Write a program that alerts the current month in words. For example December.
Write a program that alerts the first 3 letters of the current day, for example if today is Sunday then alert will show Sun.
Write a program that displays a message “It’s Fun day” if its Saturday or Sunday today.
Write a program that shows the message “First fifteen days of the month” if the date is less than 16th of the month else shows “Last days of the month”.
Write a program that determines the minutes since midnight, Jan. 1, 1970 and assigns it to a variable that hasn't been declared beforehand. Use any variable you like to represent the Date object.
Write a program that tests whether it's before noon and alert “Its AM” else “its PM”.
Write a program that creates a Date object for the last day of the last month of 2020 and assigns it to variable named later Date.
Create a date object of the starting date of this Ramadan and alert the number of days past since 1st Ramadan? Note: 1st Ramadan was on June 18, 2015
Write a program that displays in your browser the seconds that elapsed between the reference date and the beginning of 2015.
Create a Date object for the current date and time. Extract the hours, reset the date object an hour ahead and finally display the date object in your browser.
Write a program that creates a date object and show the date in an alert box that is reset to 100 years back?
Write a program to ask the user about his age. Calculate and show his birth year in your browser.
Write a program to generate your K-Electric bill in your
browser. All the amounts should be rounded off to 2
decimal places. Display the following fields:
a. Customer Name
b. Current Month
c. Number of units
d. Charges per unit
e. Net Amount Payable (within Due Date)
f. Late Payment Surcharge
g. Gross Amount Payable (after Due Date)
Write a function that displays current date & time in your browser.
Write a function that takes first & last name and then it greets the user using his full name.
Write a function that adds two numbers (input by user) and returns the sum of two numbers.
Write a function that takes three arguments num1, num2 & operator & compute the desired operation.
Write a function that squares its argument.
Write a function that computes factorial of a number.
Write a function that take start and end number as inputs & display counting in your browser.
Write a nested function that computes hypotenuse of a
right angle triangle.
Hypotenuse2 = Base2 + Perpendicular2
Write a function that calculates the area of a rectangle.
A = width * height
Pass width and height in following manner:
i. Arguments as value
ii. Arguments as variables
Write a JavaScript function that checks whether a passed string is palindrome or not? A palindrome is word, phrase, or sequence that reads the same backward as forward, e.g., madam.
Write a JavaScript function that accepts a string as a parameter and converts the first letter of each word of the string in upper case. EXAMPLE STRING : 'the quick brown fox' EXPECTED OUTPUT : 'The Quick Brown Fox'
Write a JavaScript function that accepts two arguments, a string and a letter and the function will count the number of occurrences of the specified letter within the string. Sample arguments : 'JSResourceS.com', 'o'
Write a JavaScript function that accepts a string as a parameter and find the longest word within the string. EXAMPLE STRING : 'Web Development Tutorial' EXPECTED OUTPUT : 'Development'
Create 2 functions that calculate properties of a circle, using
the definitions here.
Create a function called calcCircumference:
• Pass the radius to the function.
• Calculate the circumference based on the radius, and output
"The circumference is NN".
Create a function called calcArea:
• Pass the radius to the function.
• Calculate the area based on the radius, and output "The area
is NN".
Circumference of circle = 2πr
Area of circle = πr2