JavaScript Practice 01

resource

A) Use Firefox Browser > Firebug > Console to write your javascript program and click ‘Run’ to execute
B) Javascript syntax example for asking Input from user
* Example B.1: Here we display an input box to user with the message “Please enter your name”. We then store the entered value in the variable ‘person’

var person = prompt(“Please enter your name”, “”);

C) Javascript syntax example for showing Output
* Example C.1: we display an output box to user with the message “Go USA!!!”.

alert(“Go USA!!!”);

* Example C.2: we display an output box to user with the message “Go !!!”.
Notice we used a pre-defined variable ‘country’ to display the countryname.

country = “USA”;
alert(“Go ” + country + “!!!”);

programmingtasks

  • 1. GREETER.1: Write a program to output the welcome message below:

Hello World!

  • 2. GREETER.2: Write a program to ask user to input a name and output that name like below:
  • 3. GREETER.3: Write a program to ask user to input a name and output a welcome massage with that name like: ¬†Hello !
  • 4. CALCULATOR.1: Write a program to calculate square of a number

(n-square = n * n )

Ask user to enter a number and display it’s square.

  • 5. CALCUATOR.2: Write a program to calculate cube of a number

(n-cubed = n * n * n ).

Ask user to enter a number and display the cubed result

  • 6. CALCUATOR.3: Write a program to add 2 numbers

Ask user to enter a number and then a second number and display added result

Leave a Reply

Your email address will not be published. Required fields are marked *