Javascript Exercises:

Easy in Class Javascript group exercise:

Assemble your team of 3 for Battle!!

Team member 1:

Write a function (function1) that expects two parameters, the first one, a string, the second one, a number.
The function should modify an element with an id of "demo" with the string parameter repeated the amount of the number parameter received.

Write this function in an external javascript file and host/upload it on your free web host (in a new folder if you want).

Team member 2:

Write a function (function2) that will accept a number. If the number is equal to zero (0), it should return the value "bye",
if it is one (1) it should return the value "hello", otherwise it should return the value "Welcome"

Write this function in an external javascript file and host/upload it on your free web host (in a new folder if you want).

Team member 3:

Create an HTML file and import the external scripts with the containing functions.
Use a form or prompt to get the two parameters required by function1. Then When a button is clicked use function1 to modify a paragraph with the id of "demo".
Do the same for function2 and alert the user with the value returned from the function when a heading of your choice is clicked

Host/upload this file on your free web host (in a new folder if you want).

Easy Javascript coding:

First create a simple website with the largest heading with the text "Hello World" and an id attribute with a value of your choice.

Use Javascript to change this website as follows:

  1. Prompt to enter your name and change the heading text to read "Hello" plus the entered name.
  2. Write a javascript program to print the numbers from 1 to 100 to the webpage. You must use at least one function.
  3. Modify the program to store the numbers 1 to 100 in an array.
  4. Create an object with at least 5 attributes and 2 methods. The two methods should return an attribute value.
  5. Write a script to count the number of times a button is clicked and alert the user if the button was clicked more than 5 times.
  6. Write a script to add two numbers entered by a user using the prompt method.
  7. Write a script to prompt the user for a number between 1 - 10 if the number is NOT 5 the script will print your name to the screen and prompt for another number between 1-10 until you enter 5.
  8. Write a script to modify an <h1> tag with your name when it is clicked. The h1 tag should read "hello world" initially.
  9. Make a simple web page that contains a button and a paragraph with the id of count. Whenever this button is pressed increment the count by 1 and update the paragraph text. Also update the font size so that as the number gets larger, so does the font.
  10. Make a simple web page that contains an h2 heading with the word "Hello", a text input box, and a button. When the user types a word or phrase into the input box and presses the button, replace the old h2 with the word entered. Also make the word spin.
  11. Select ONE of the following:

  12. Build a calculator which has buttons for you to click and displays the calculated answer. The calculator should be able to perform the following operations:
    -Addition
    -Multiplication
    -Division
    -Powers of 2 (NB 2^n - 2^1 = 2 2^2=4 2^3=8)
  13. Modify the B-One supermarkets website you previously created, to have a functional shopping cart. Be creative, here are some suggestions:
    1. keep track of items in stock as they are sold are added to cart
    2. When an item is out of stock, either make the item disappear or display out of stock
    3. Let the user view the shopping cart
    4. Let the user proceed to checkout and enter user information, e.g. (fictitious) credit card number and store it
    5. Use form validation techniques to decide whether the credit card is valid, e.g. length of 7 numbers not less than 1000000
    6. Display a successfull order message
    7. You may even include a separate webpage that can display a table of user information with the items ordered for the cashiers/delivery personnel to run the credit card information and begin delivery
    8. You can even allow orders to be deleted by the sales staff when they are complete.