07
  • Lab Exercise

    Create a Folder called : ‘JS_Lab1’

    Exercise 1

    Create a web page : Ex1.htm

    The web page which will do the following :
    Prompt the user for their Favourite City
    Prompt the user for their Favourite Singer/Band
    Display both using on web page using Document.write

    For example : Your Favourites are Glasgow and Bruce Springsteen

    Exercise 2

    Copy Form_Example.htm from the zip file – and save file as Ex2.htm

    Using a Text Box and a Button - the User must input a mark between 1 and 10
    Using an Alert Box – display the actual mark out of 100
    e.g user types in 4 … the Alert Box will display “ Your actual mark is 40”

    A Function MUST be used
    Ensure validation is used to check the user input and to display an error message if it is not a number between 1 and 10

    It should be similar to this :

    Mark Input Box Example

    Exercise 3

    Copy Form_Example.htm from the zip file – and save file as Ex3.htm

    Add another Text Box (it must have a different ID)
    The User will input ANY number into both boxes
    Use Alert to display the Total
    e.g User types in 3 and 5 - the Alert Box will display “ The total is 8”
    The Button should be called “ADD”
    Use validation to check that (both) text boxes contain a number

    Hint :
    Check first number
    Display error message if first number is invalid
    Otherwise :
    Check second number
    Display error message if second number is invalid
    Otherwise
    Both numbers are valid - so add and display total

    It should be similar to this :

    Number Input Boxes Example

    Exercise 4

    Save Ex3.htm as Ex4.htm
    Add a Button called “Multiply”
    This will be very similar to “ADD” – but will multiply both numbers
    e.g User types in 3 and 5 - the Alert Box will display …. “The answer is 15”
    Add a new function to multiply both numbers
    The MULTIPLY button should have a different ID and Value. It should also call the new ‘multiply’ function

    Ensure that both the ADD and MULTIPLY buttons work correctly

    It should be similar to this :

    Number Input Boxes Example 2

    💡 Download Example Files
  • Lynda.com Videos

    Week 7

    8. Basic Scripting
    will be covered during Javascript
    HTML and JavaScript (4m 51s)
    The script element (5m 56s)
    Writing a function (4m 8s)
    Using the DOM (6m 30s)
    Listening for an event (6m 49s)
    Responding to events (5m 30s)
    Externalising JavaScript (5m 15s)
    Conclusion
    Next steps (2m 17s)