Problem Solving Practice by JavaScript
By: Md Touhedul Haque
Tags: Js, Javascript Development, Javascript Tips, Problem Solving, JavaScript

problem-solving by JS

True VS False? (Truthy and Falsey values):

Answer:

Automatic False Situations:

# when value is 0. # when value is “” (without underscore). # when value is undefined. # when value is null. # when value is NaN.

Automatic True Situations:

# when value is ‘0’ # when value is “ ” (underscore inside) #when declare empty object or array {} [].

for example:

vs-code

Output is // false

2. Null Vs Undefined?

Answer: #Undefined# There are several ways (by mistake), we will get “undefine” for example:

vs-code

*Here age has no parameter.

vs-code

**Here we will get result and also get undefine cause above function has no return.

vs-code

**Here num1 value is 13 but num2 has no value. for this we will get output 13 and undefine.

vs-code

** Here johnTrendy has a name & tel. but when we want to know his age the value is undefined because age is not defined before.

“undefine” is negative that’s why it is false.

##Null##

*null means empty.

*developers define some value is null.

null has to set, normally it’s not showing as an output.

3. (===)triple equal VS (==)?

Answer:

vs-code

## double equal (==) never check string type, on the other hand triple equal (===) always check value and string type. according to standard better to use triple equal (===).

vs-code

## another example of double equal (==)

vs-code

4. Make a function of feet to mile?

answer:

Information: //feetToMile // info: 1 mile = 5280 feet

function feetToMile(feet) {

var mile = feet / 5280;

return mile;

}

var result = feetToMile(90000);

result = result.toFixed(2)

//**extra part for bonus marks .toFixed */console.log(“Mile is:”, result)

5. Make a function of the wood calculator (How many total blocks of wood we need to make 3 things)?

Answer:

Information:

//woodCalculator info: chair = 1 ci, table = 3 ci; bed = 5 ci (ci = cubic inches)

Solution:

function woodCalculator(chair, table, bed) {

var chairWoodCount = chair * 1;

var tableWoodCount = table * 3;

var bedWoodCount = bed * 5;

var totalWood = chairWoodCount + tableWoodCount + bedWoodCount; return totalWood;

}

var totalWoodResult = woodCalculator(11,2,3);

console.log(“Total Wood Need in Cubic Inches:”, totalWoodResult);

6. Find the max number from two values?

Answer:

let a=950;

let b=350;

let c=550;

let max = Math.max(a,b,c)

console.log(max)

7. Find the largest number from three values by control flow (if, nested if)?

solution:

let n1 = 56.98888888;

let n2 = 66.98888888;

let n3 = 99.9999999999999999999999;

n1 = parseInt(n1);

n2 = parseInt(n2);

n3 = parseInt(n3);

/////////

if (n1 >= n2) {

if (n1 >= n3) {

console.log(n1 + " is the largest")

} else {

console.log(n3 + " is the largest")

}

} else {

if (n2 >= n3) {

console.log(n2 + " is the largest")

} else {

console.log(n3 + " is the largest")

}

}

8. Basic Grading system by if-else statement?

Answer:

vs-code

8. Series of a square number and it’s sum value by loop function. for example: 3 is number and it’s series value of square number is 1+4+9 = 14?

Answer:

vs code

change the input number (x value) and you will find the result. Thanks

Written By & Best Regards