-
Notifications
You must be signed in to change notification settings - Fork 0
/
sumDigitsSlider.html
executable file
·224 lines (189 loc) · 6.01 KB
/
sumDigitsSlider.html
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!DOCTYPE html>
<html>
<head>
<title>Digits Slider | Evan Genest</title>
<meta charset="utf-8">
<link rel="icon" href="./images/dryer.png" type="image/x-icon">
<style type="text/css">
@font-face {
font-family: Gin;
src: url(./fonts/gin.ttf) format('truetype');
}
@font-face {
font-family: OPTIFirminDidot;
src: url(./fonts/OPTIFirminDidot.otf);
}
:root {
--accent-r: rgb(156, 0, 17 );
--accent-b: rgb(23, 76, 116 );
--accent-g: rgb(25, 86, 39 );
--accent-w: rgb(242, 188, 133 );
}
html {
height:100%;
width: 100%;
color: var(--accent-w);
font-family: monospace;
}
.letters {
font-family: Gin;
/* padding-top: ;
padding-bottom: 0.2rem !important;
*/
}
.numbers {
font-family: OPTIFirminDidot, Helvetica, Arial;
font-size: 3rem;
color: white;
/* padding-top: 0.28rem !important;
padding-bottom: 0rem !important;
*/ /* day after the interview, I find a case where !important required ! */
}
.monde {
/*==f=i=l=l==s=c=r=e=e=n==================*/
min-height: 100%;
width: 100%;
height: auto;
/* Set up positioning */
position: fixed;
display: flex; /*(1)VERT*/
flex-direction: column; /*(1)VERT*/
align-items: center; /*(1)VERT*/
justify-content: center; /*(2)HORIZ*/
}
.square-large {
background: url(./images/abacus_397x528.png) no-repeat fixed center;
border-radius: 2rem;
border: solid var(--accent-b) 0.4rem;
height: 28rem;
width: 28rem;
display: flex; /*(1)VERT*/
flex-direction: row; /*(1)VERT*/
align-items: center; /*(1)VERT*/
justify-content: center; /*(2)HORIZ*/
}
.square-small {
width: 55%;
display: flex; /*(1)VERT*/
flex-direction: column; /*(1)VERT*/
align-items: center; /*(1)VERT*/
}
.out-stripe {
border-radius: 1.2rem;
background-color: var(--accent-g);
margin: 1.8rem 2.4rem;
padding: 1.6rem;
text-align: center;
opacity: 0.98;
}
.slider-holder {
background-color: var(--accent-b);
opacity: 0.98;
border-radius: 1.2rem;
margin: 1.7rem;
display: flex;
align-items: center;
width: 4.5rem;
text-align: right;
font-family: Gin;
}
}
.line {
display: inline-block;
}
.block {
display: block;
}
.wide {
width: 8rem;
}
.skinny {
width: 3rem;
}
input.vertical {
-webkit-appearance: slider-vertical;
writing-mode: bt-lr;
height: 9rem;
width: 2rem;
cursor: pointer;
}
</style>
<script type="text/javascript">
/*
Given a non-negative int n, return the sum of its digits recursively (no loops). Note that mod (%) by 10 yields the rightmost digit (126 % 10 is 6), while divide (/) by 10 removes the rightmost digit (126 / 10 is 12).
sumDigits(126) → 9
sumDigits(49) → 13
sumDigits(12) →
*/
function adder(n) {
return n * n;
}
function putNumber() {
const el3 = document.getElementById('numberRequested');
el3.innerHTML = "13";
}
function showSumOfDigits(){
let el3 = document.getElementById('slider-1'); // removed LET
console.log(el3.value + "is a slider value");
// send the slider number to the summit function, get an object back
let results = summit(el3.value);
let el2 = document.getElementById('before-panel');
el2.innerHTML = el3.value;
let el4 = document.getElementById('after-panel');
el4.innerHTML = summit(el3.value).after;
}
function summit(n) {
// Get it? "Some It" ?
// Could write as recursive instead of array. probably computationally faster,
// ...but strategy below is easier to write and read.
// Handle case where only single digit input
if (n < 10 ){
return { "before": n.toString(), "after": n};
}
let stringNum = n.toString();
console.log(typeof stringNum);
let numChars = stringNum.split('');
console.log(numChars);
console.log(`Adding first two array CHARS gives ${Number(numChars[0]) + Number(numChars[1])}...`);
let sum = numChars.reduce((accum, char)=>{
console.log(char);
return accum + Number(char);
}, 0);
// return an object
return {
"before": stringNum,
"after": sum
};
}
// Initialize the slider and fire the output script once
document.addEventListener('DOMContentLoaded', (event)=>{
console.log("hie");
let el3 = document.getElementById('slider-1');
el3.value = 13;
showSumOfDigits();
})
console.log('one');
</script>
</head>
<body>
<div class="monde">
<h1>d i g i t s s l i d e r</h1>
<div class="square-large">
<div class="slider-holder">
Slide this:
<input class=" vertical" id="slider-1" orient="vertical" type="range" onchange="showSumOfDigits()" value="7" min="0" max="10000" />
</div>
<div class="square-small">
<div class="out-stripe"> <label class="block inverse letters">If you add up the digits in: </label>
<output class="block skinny inverse numbers" id="before-panel"></output></div>
<div class="out-stripe">
<label class="block inverse letters">You get this sum: </label>
<output class="block skinny inverse numbers" id="after-panel">null</output>
</div>
</div>
</div>
<a style="background-color:white; color:white;text-decoration:none;padding:0;font-family:monospace;font-size:1px;line-height:1px;display:inline-block;border-radius:0" href="https://unsplash.com/@crissyjarvis?utm_medium=referral&utm_campaign=photographer-credit&utm_content=creditBadge" target="_blank" rel="noopener noreferrer" title="Download free do whatever you want high-resolution photos from Crissy Jarvis">Crissy Jarvis</span>
</a>
</div>
</body>
</html>