-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment.js
96 lines (89 loc) · 2.14 KB
/
assignment.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Problem:1 radianToDegree
function radianToDegree(radian)
{
if(typeof radian !== "number")
{
return 'Error . Input a number';
}
return ((radian*180)/Math.PI).toFixed(2);
}
console.log(radianToDegree(10));
// Problem:2 isJavaScriptFile
function isJavaScriptFile(String)
{
if(typeof String !== "string")
{
return 'Error . Input a number';
}
else if(String.endsWith('.js'))
{
return true ;
}
else
return false ;
}
console.log(isJavaScriptFile('Arif.cs'));
//Problem 3: oilPrice
function oilPrice(x,y,z)
{
const perLitreDiselPrice =114;
const perLitrePetrolPrice = 130;
const perLitreOctanePrice = 135;
if((typeof x !=="number")||(typeof y !=="number")||(typeof z !=="number"))
{
return 'Error . Input number';
}
return x*perLitreDiselPrice+y*perLitrePetrolPrice+z*perLitreOctanePrice;
}
console.log(oilPrice('x',20,10));
// Problem 4: publicBusFare
function publicBusFare(x)
{
const busCapacity = 50;
const microCapacity = 11;
let Check = 0; // to check how many bus and micro will be used
let remaining ; // to check how many passenger will remaining
if(typeof x !== 'number')
{
return 'Error . Input a number';
}
if(x<=50)
{
return 0;
}
else if(x>50)
{
for(let i=1;busCapacity*i<x ; i++)
{
Check += busCapacity;
}
remaining = x-Check;
for(let i=1; microCapacity*i<remaining; i++)
{
Check +=microCapacity;
}
remaining = x-Check;
return 250*remaining;
}
}
console.log(publicBusFare(50));
// Problem 5: isBestFriend
function isBestFriend(object1,object2)
{
if((typeof object1 !== 'object')||(typeof object2 !== 'object'))
{
return 'Error . Input an object';
}
if(((object1.name.localeCompare(object2.friend))===0)&&((object2.name.localeCompare(object1.friend))===0))
{
return true;
}
return false ;
}
const object1 = {
name :'abul', friend : 'kabul'
}
const object2 = {
name : 'kabul', friend : 'sabul'
}
console.log(isBestFriend(object1,object2));