Table of Content
- Program To Print Hello World
- Program to Add Two Numbers
- Program to Swap Two Variables
- Program to Convert Kilometers to Miles
- Program to Convert Celsius to Fahrenheit
1) Program To Print Hello World
1.Using console.log() |
---|
|
2. Using alert() |
|
3. Using document.write() |
|
2)Program to Add Two Numbers
1.Add Two Numbers |
---|
|
2.Add Two Numbers Entered by the User |
|
3)Program to Swap Two Variables
1.Using a Temporary Variable |
---|
|
2.Using es6(ES2015) Destructuring assignment |
//JavaScript program to swap two variables
//take input from the users
let a = prompt('Enter the first variable: ');
let b = prompt('Enter the second variable: ');
//using destructuring assignment
[a, b] = [b, a];
console.log('The value of a after swapping: ${a}');
console.log('The value of b after swapping: ${b}');
4)Program to Convert Kilometers to Miles
Kilometers to Miles |
---|
|
Miles to Kilometers |
|
5)Program to Convert Celsius to Fahrenheit
Celsius to Fahrenheit |
---|
|
Fahrenheit to Celsius |
|
Tags:
JavaScript