-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJS_extra.js
More file actions
53 lines (45 loc) · 1.29 KB
/
Copy pathJS_extra.js
File metadata and controls
53 lines (45 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Print pyramid
// *
// ***
// *****
// *******
// *********
//! Print this pattern.
const pyramid = n =>{
for(let i = 1; i <=n; i++){
console.log(' '.repeat(n-i) + '*'.repeat( 2 * i - 1))
}
};
console.log(pyramid(5));
//! How to calculate twon numbers without using any arethmetic operator.
function additionOfTwoNumbers(a,b){
for(i = 1; i <= b; i++){
a++;
}
return a;
}
console.log(additionOfTwoNumbers(50,30));
//! multiplication, subtraction, division without using any arithmetic operator.
function subtractionOfTwoNumbers(a,b){
for(i = 1; i <= b; i++){
a--;
}
return a;
}
console.log(subtractionOfTwoNumbers(-20,-30));
function multiplicationOfTwoNumbers(a,b){
let result = 0;
for(i=1; i<=b; i++){
result += a;
}
return result;
}
console.log(multiplicationOfTwoNumbers(10,20));//This code can be updated for the values that are negative and if both the values are negative also.
function divisionOfTwoNumbers(a,b){
let result = 0;
for(;a >= b; result++){
a -= b;
}
return parseFloat(result);
}
console.log(divisionOfTwoNumbers(20,10));//This code can be updated for decimal values in the result as well as to handle the negative values also.