-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
160 lines (139 loc) · 4.16 KB
/
example.js
File metadata and controls
160 lines (139 loc) · 4.16 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
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
"use strict"
// document.write("Jared Burks");
// console.log("24");
// alert("Wisconsin");
//worker pay calculator
// var workerAhours = 34;
// var workerBhours = 47;
// var workerApay = 17.24;
// var workerBpay = 23.43;
// var weeklyPayA = workerAhours*workerApay;
// var weeklyPayB = workerBhours*workerBpay;
//using functions with these 3 variables
// var hours = prompt("Type in your hours: ");
// var pay = prompt("Type in your pay rate: ");
// var weeklyPay = hours*pay;
// function payCalculator(hours,rate){
// if(hours<=40){
// var final = parseFloat(Math.round(weeklyPay * 100) / 100).toFixed(2);
// console.log(final);
// alert("Weekly Pay is: $" + final);
// }
// else if(hours>40){
// var overtime = hours-40;
// hours = hours - overtime;
// weeklyPay = hours * pay;
// var extraPay = overtime * pay*1.5;
// weeklyPay = (extraPay + weeklyPay).toFixed(2);
// console.log(weeklyPay);
// alert("Weekly Pay is: $" + weeklyPay);
// }
// }
// payCalculator(hours, pay);
//below is a way to display single digits with 2 decimal places. Example 1 would be 1.00
// var result = parseFloat(Math.round(3 * 100) / 100).toFixed(2);
// console.log(result);
// if(workerAhours<40){
// console.log(weeklyPayA);
// }
// else if(workerAhours>40){
// var workerAovertime = workerAhours-40;
// workerAhours = workerAhours - workerAovertime;
// weeklyPayA = workerAhours * workerApay;
// var workerAextra = workerAovertime * workerApay*1.5;
// weeklyPayA = (workerAextra + weeklyPayA).toFixed(2);
// //weeklyPayA = weeklyPayA.toFixed(2);
// console.log(weeklyPayA);
// }
// if(workerBhours<40){
// console.log(weeklyPayB);
// }
// else if(workerBhours>40){
// var workerBovertime = workerBhours-40;
// workerBhours = workerBhours - workerBovertime;
// weeklyPayB = workerBhours * workerBpay;
// var workerBextra = workerBovertime * workerBpay*1.5;
// weeklyPayB = (workerBextra + weeklyPayB).toFixed(2);
// //weeklyPayB = weeklyPayB.toFixed(2);
// console.log(weeklyPayB);
// }
// //fizzbuzz
// for(var i = 0; i <= 100; i++){
// if(i===0){
// console.log(i);
// }
// else 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);
// }
// }
//Javascript problem 3. Capitalize 1st character of each word seperated by a space.
// var userString = prompt("Type some words: ");
// function bigLetters(){
// var userArray = userString.split(" ");
// //console.log(userArray);
// for(var i = 0 ; i < userArray.length ; i++){
// userArray[i] = userArray[i].charAt(0).toUpperCase() + userArray[i].substr(1);
// }
// alert(userArray.join(" "));
// }
// bigLetters();
//failing at this(problem 4), ganna try something different below.
// function compression(){
// var str = prompt("Type Letters: ");
// var initalChar = str.charAt(0);
// var count = {};
// for(var i = 0; i < str.length; i++){
// var currentChar = str[i];
// if(count[currentChar]){
// count[currentChar]++;
// }
// else{
// count[currentChar] = 1;
// }
// }
// console.log(count);
// console.log(Object.keys(count));
// console.log(Object.values(count));
// console.log(count.a);
// alert(JSON.stringify(count));
// }
// compression();
//Javascript problem 4
function compression(){
var str = prompt("Type Letters: ");
var initalChar = str.charAt(0);
var count = 0;
var compressedStr = "";
for(var i = 0; i < str.length; i++){
var currentChar = str[i];
if(initalChar === currentChar){
count++;
}
else if(count === 1){
compressedStr += initalChar;
initalChar = currentChar;
}
else{
compressedStr += count + initalChar;
initalChar = currentChar;
count = 1;
}
}
if(count ===1){
compressedStr += currentChar;
}
else{
compressedStr += count + currentChar;
}
console.log(compressedStr);
}
compression();