-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (47 loc) · 1.33 KB
/
index.js
File metadata and controls
65 lines (47 loc) · 1.33 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
54
55
56
57
58
59
60
61
62
63
64
65
//jshint esversion:6
// question 1
var obj = {
name: "Joshua",
hobby: "Being good",
age: 19,
toString: Object.prototype.toString
};
var str = obj + "";
console.log(str);
var objToString = function(obj, indent) {
obj = obj || this;
indent = indent || "";
var res = "";
for (var k in obj) {
if (typeof obj[k] == "object") {
res += indent + k + " = {\n";
res += objToString(obj[k], indent + "- ");
res += indent + "}";
} else if (typeof obj[k] != "function") {
res += indent + k + " = " + obj[k];
} else {
continue;
}
res += "\n";
}
return res;
};
obj.toString = objToString;
obj + "";
//question 3
function eligible(_mile, _membership) {
if (_mile < 2 && _membership == "active") {
console.log("Not eligible for free delivery");
} else if (_mile < 11 && _membership == "active") {
console.log("Eligible");
} else {
console.log("Not eligible!!!");
}
}
//question 4
function user_input(input1) {
var con = Number(input1); //converts the input to number if inputed as string
var n = con.toFixed(2); //does the approximation to 2 decimal places
var out = console.log("$" + n);
}
// question5