-
Notifications
You must be signed in to change notification settings - Fork 0
/
0.09_functions.js
170 lines (121 loc) · 3.28 KB
/
0.09_functions.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
function setLine () {
// body...
console.log("----------------------")
}
function hello () {
console.log("Hello World");
}
hello();
// making a function with greeting
function greeting(name){
// console.log() should not be called by a console.log('')
return "Greetings " + name;
}
var addGreeting = greeting("Cam") + ", how are you doing today";
console.log(addGreeting);
// adding number to function
function printNumber(){
return 1;
}
printNumber();
// math
function sumNum(x, y){
return x + y;
}
function divNum(x, y){
return x / y;
}
function mulNum(x, y){
return x * y;
}
function subNum(x, y){
return x - y;
}
//console.log(num1); - wont work because it is calling var inside of function - not a global var
// console.log(sumNum + divNum + mulNum + subNum); - This will print out the functions - Why?
function subTwoNum (x, y) {
var diff = x - y;
return diff;
}
// subTwoNum(4,3);
// subNum(4,3);
// sumNum(4,3);
// divNum(4,3);
// mulNum(4,3);
function calculatePriceIndiana (quantity, price, tax) {
// var tax = 0.07;
var totalTax = quantity * price * tax;
var totalPrice = totalTax + quantity * price;
return (totalPrice);
}
console.log(calculatePriceIndiana(17, 5, 0.07));
// built in Objects example
var today = new Date();
console.log(today.toDateString());
function checkOdd (num) {
if (num % 2 === 0) {
return "This number " + num + " is even";
}
else {
return "This number " + num + " is odd";
}
// if odd there will be a remainder of 1
}
console.log(checkOdd(200000));
function divByThree (num) {
if (num % 3 === 0) {
return "This number " + num + " is 'three'ish'";
}
else {
return "This number " + num + " is not 'three' friendly";
}
}divByThree
console.log(divByThree(36));
var name
var adamGreet = " bummer life dude";
var samGreet = " ready for the climb?";
function greeting2 (name) {
if (name == "Adam") {
return name + adamGreet;
} else if (name == "Sam"){
return name + samGreet
}
}
var addGreeting = greeting2("Adam");
console.log(addGreeting)
// Write a function with two strings as parameters.
// The function should concatenate the string.
// Write a function that will help me easily calculate monthly bills.
// Write a function that takes quantity, price, tax and an item
// The function should take the quantity, price, tax and the item name and return
// a response similar to this.
// --150 hotdogs will cost you $145 (your math may not be perfect and may
// potentially return 145.457. If that is the case, don’t sweat it.
// Gold
function hotDogs (quantity, price, tax, name) {
// var tax = 0.07;
var totalTax = quantity * price * tax;
var totalPrice = totalTax + quantity * price;
return ("total price is " + Math.round(totalPrice) + " for the"+ name);
}
console.log(hotDogs(150, .92, 0.07, " hotDogs"));
// Silver
function monBills (gas, water, electric, internet, food) {
var utility = gas + water + electric;
var other = internet + food
var totalsBil = utility + other;
return totalsBil;
}
console.log(monBills(10, 10, 10, 10, 10));
// Bronze
function myName (firstName, lastName) {
fullName = firstName +" "+ lastName
console.log(fullName);
}
myName("Cameron", "Houser");
setLine();
function twoStings (name1, name2) {
return name1 +" " + name2
}
console.log(twoStings("nevermore", "nevermore"))
setLine();