0% found this document useful (0 votes)
8 views

JAVASCRIPT

Uploaded by

bmmani2006
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

JAVASCRIPT

Uploaded by

bmmani2006
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

JAVASCRIPT-TODAY TOPIC

1)
const number1 = 2.25;
const number2 = -4;
const number3 = 'hello';

const result1 = Math.sqrt(number1);


const result2 = Math.sqrt(number2);
const result3 = Math.sqrt(number3);

console.log(`The square root of ${number1} is ${result1}`);


console.log(`The square root of ${number2} is ${result2}`);
console.log(`The square root of ${number3} is ${result3}`);

2)
// function that returns product of two numbers
function product(a, b) {
return a * b;
}

// Calling product() function


let result = product.call(this,20, 5);

console.log(result);

3)
var b=20;
let c=30;
function f() {

// It can be accessible any


// where within this function
var a = 10;
console.log(a);
}
f();
function fun1()
{
let x1=100;
console.log(x1);
console.log(a);
}

fun1();
// A cannot be accessible
// outside of function
//console.log(a);

4)
console.log("basic function");
const num1 = 5;
const num2 = 3;
// add two numbers
const sum = num1 + num2;

// display the sum


console.log('The sum of ' + num1 + ' and ' + num2 + ' is: ' + sum);

5)
const side1 = parseInt(prompt('Enter side1: '));
const side2 = parseInt(prompt('Enter side2: '));
const side3 = parseInt(prompt('Enter side3: '));

// calculate the semi-perimeter


const s = (side1 + side2 + side3) / 2;

//calculate the area


const areaValue = Math.sqrt(
s (s - side1) (s - side2) * (s - side3)
);

console.log(
`The area of the triangle is ${areaValue}`
);

6)
const side1 = parseInt(prompt('Enter side1: '));
const side2 = parseInt(prompt('Enter side2: '));
const side3 = parseInt(prompt('Enter side3: '));

// calculate the semi-perimeter


const s = (side1 + side2 + side3) / 2;

//calculate the area


const areaValue = Math.sqrt(
s (s - side1) (s - side2) * (s - side3)
);

console.log(
`The area of the triangle is ${areaValue}`
);

7)
let a = 10;
function f() {
let b = 9
console.log(b);
console.log(a);
}
f();
console.log(a);

8)
let a = 10;
function f() {
if (true) {
let b = 9

// It prints 9
console.log(b);
}

// It gives error as it
// defined in if block
console.log(a);
}
f()

// It prints 10
console.log(a)

9)
const a = 10;
function f() {
a=9
console.log(a)
}
f();

10)
let name = "John"; // String
let age = 30; // Number
let bigNumber = BigInt("1234567890123456789012345678901234567890"); // BigInt
let isStudent = false; // Boolean
let x; // Undefined
let y = null; // Null
let id = Symbol("id"); // Symbol

11)
// numeric string used with + gives string type
let result;

// convert number to string


result = "3" + 2;
console.log(result, "-", typeof(result));

result = "3" + true;


console.log(result, "-", typeof(result));

result = "3" + null;


console.log(result, "-", typeof(result));

12)
let employee = {
details: function (designation, experience) {
return this.name
+""
+ this.id
+ designation
+ experience;
}
}

// Objects declaration
let emp1 = {
name: "A",
id: "123",
}
let emp2 = {
name: "B",
id: "456",
}
let x = employee.details.call(emp2, " Manager ", "4 years");
console.log(x);

13)
const number = prompt("Enter a number: ");
if (number >= 0) {
if (number == 0) {
console.log("The number is zero");
} else {
console.log("The number is positive");
}
} else {
console.log("The number is negative");
}
14)
const number = parseInt(prompt("Enter a number: "));
// check if number is greater than 0
if (number > 0) {
console.log("The number is positive");}
// check if number is 0
else if (number == 0) {
console.log("The number is zero");
}
// if number is less than 0
else {
console.log("The number is negative");
}

15)
hi you use prompt u must declared with code:

const prompt = require('prompt-sync')();

const name = prompt('What is your name? ');


console.log(`Hello, ${name}!`);

You might also like