-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (35 loc) · 1 KB
/
script.js
File metadata and controls
39 lines (35 loc) · 1 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
//Task One
class PrettyPrint {
constructor() {/*alert(this)*/}
toString() {
return "[object Fad]"
}
}
// var p = new PrettyPrint();
// alert(p)
//Task Two
function isEligible(no_of_miles_away, is_a_member) {
if(typeof no_of_miles_away !== "number") {
throw new Error("Please provide a number for customer's location in miles away");
}
let eligibility = false;
if(no_of_miles_away > 1 && no_of_miles_away <= 5) {
eligibility = true;
} else if(no_of_miles_away <= 10 && is_a_member) {
eligibility = true
}
console.log(eligibility
? "Congratulation! Ypu qualify for free delivery"
: "Sorry, free delivery is not available in your location!");
return eligibility;
}
// alert (is Eligible(9, true))
//Task Three
function formatPrice(price, currency) {
price = Number(price); //Convert to number in case its a string
if(isNAN(price) || typeof currency !== "string") {
throw new Error("Please supply current arguments");
}
return ${currency}${price.toFixed(2)};
}
//alert(formatPrice(21, "$"))