-
Notifications
You must be signed in to change notification settings - Fork 0
/
practiceJS.js
151 lines (115 loc) · 3.72 KB
/
practiceJS.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
// strings and manipulation of them
// var message = prompt("Enter your message.");
// var used = message.length;
// alert("You have used " + used + " characters. You have " + 180-used + " characters left.");
// alert("Your new message is " + message.slice(0, 181));
// var name = prompt("Enter your name.");
// var newname;
// var firstLetter= name.slice(0,1).toUpperCase();
// var restOfName = name.slice(1,name.length).toLowerCase();
// newname = firstLetter + restOfName;
// alert("Hello " + newname + ", Welcome to the course.");
// practicing multiple operators and order of operations
// var dogAge = prompt("Enter your dog's age.");
// var dogHumanAge = (dogAge - 2) * 4 + 21;
// alert("Your " + dogAge + " year old dog is "+ dogHumanAge +" years old in human age.");
// practicing functions -- with parameters
// function getMilk(money) {
// var costOneBottle = 1.50;
// var buyBottles = parseInt(money / 1.50);
// console.log("leaveHouse");
// console.log("moveRight");
// console.log("moveRight");
// console.log("moveUp");
// console.log("moveUp");
// console.log("moveUp");
// console.log("moveUp");
// console.log("moveRight");
// console.log("moveRight");
// console.log("buy " + buyBottles + " bottles of milk.");
// console.log("moveLeft");
// console.log("moveLeft");
// console.log("moveDown");
// console.log("moveDown");
// console.log("moveDown");
// console.log("moveDown");
// console.log("moveLeft");
// console.log("moveLeft");
// console.log("enterHouse");
// }
// getMilk(5.50);
// practicing random nums
// prompt("What is your name?");
// prompt("What is your crush's name?");
// var loveScore = Math.random() * 100;
// loveScore = Math.floor(loveScore) + 1;
// if (loveScore > 70){
// alert("Your love score is " + loveScore + "%. You love each other like Kanye loves Kanye.");
// } else{
// alert("Your love score is " + loveScore + "%.");
// }
// simple program for practicing arrays
var name = prompt("Enter your name.");
var guests = ["john", "mary", "dawn"];
if (guests.includes(name)){
alert("Welcome " + name + "!");
} else {
alert("nah, get outta here.");
}
// print 1-100, multiple of 3 - fizz, 5 - buzz, both- FizzBuzz
for (let i = 1; i < 101; i++){
if ((i % 3 === 0) && (i%5===0)){
console.log("FizzBuzz");
}
else if (i % 3 === 0){
console.log("Fizz");
}
else if (i%5===0){
console.log("Buzz");
} else{
console.log(i);
}
}
// var heading = document.lastElementChild.firstElementChild
// heading.innerHTML="Good bye";
// document.querySelector("ul").lastElementChild.innerHTML = "Jessieee";
// var items = document.querySelectorAll("li");
// undefined
// items[0].firstElementChild.color = "red";
// items[0].firstElementChild
// <a href="https://wwww.google.com">Google</a>
// items[0].firstElementChild.style.color = "red";
// working with higher order functions
function add(num1, num2){
return num1+num2;
}
function divide(num1, num2){
return num1/num2;
}
function multiply(num1, num2){
return num1*num2;
}
function subtract(num1, num2){
return num1+num2;
}
function calculator(num1, num2, operator){
return operator(num1, num2);
}
// working with data structure (dictionary)
// var houseMaid1 = {
// name: "Maria",
// yearofExperience: 12,
// duties: ["bathroom", "lobby", "bedroom"]
// }
// houseMaid1.name;
// constructor function (acts like a class - i think)
function HouseMaid(name, yearsofExperience, duties){
this.name = name;
this.yearsofExperience = yearsofExperience;
this.duties = duties;
this.clean = function () {
alert("Cleaning in progress...");
}
}
var houseMaid2 = new HouseMaid("Mary", 20, ["stairs", "kitchen"]);
houseMaid2.clean();