FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
100DaysOfCoding/mathMethods/script.js at master · chini5ko/100DaysOfCoding · GitHub
chini5ko
100DaysOfCoding
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
100DaysOfCoding
/
mathMethods
/
script.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
209 lines (163 loc) · 5.76 KB
Breadcrumbs
100DaysOfCoding
/
mathMethods
/
script.js
Copy path
File metadata and controls
209 lines (163 loc) · 5.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/**
//testing
//random
for(var i=0;i<20;i++){
//console.log( Math.floor((Math.random() * 10) + 1))
}
var x1 = 3;// Math.floor((Math.random() * 10) + 1);
var y1 = 2;// Math.floor((Math.random() * 10) + 1);
var x2 = 7;// Math.floor((Math.random() * 10) + 1);
var y2 = 1;// Math.floor((Math.random() * 10) + 1);
console.log( x1 + " ," + y1 + ") , " + "(" + x2 + " ," + y2 );
*/
var
x1
=
Math
.
floor
(
(
Math
.
random
(
)
*
10
)
+
1
)
;
var
y1
=
Math
.
floor
(
(
Math
.
random
(
)
*
10
)
+
1
)
;
var
x2
=
Math
.
floor
(
(
Math
.
random
(
)
*
10
)
+
1
)
;
var
y2
=
Math
.
floor
(
(
Math
.
random
(
)
*
10
)
+
1
)
;
//slope undefined, therefore the line is vertical
while
(
x2
-
x1
==
0
)
{
// x1 =1;// Math.floor((Math.random() * 10) + 1);
// x2 =1;// Math.floor((Math.random() * 10) + 1);
x1
=
Math
.
floor
(
(
Math
.
random
(
)
*
10
)
+
1
)
;
x2
=
Math
.
floor
(
(
Math
.
random
(
)
*
10
)
+
1
)
;
console
.
log
(
"they were equal"
)
;
}
var
generatedEquationSlope
=
getSlopeThatPassedThrough2Points
(
x1
,
y1
,
x2
,
y2
)
;
generatedEquationSlope
=
Math
.
round
(
100
*
generatedEquationSlope
)
/
100
;
// round X to hundredths round X to hundredths
console
.
log
(
"slope submit: "
+
generatedEquationSlope
)
;
var
bEquation
=
getBFromSlopeEquation
(
)
;
//9
console
.
log
(
"bEquation: "
+
bEquation
)
;
console
.
log
(
getSlopeEquationAsString
(
)
)
;
//****Button********//
function
findSlope
(
)
{
//rotate the image
rotate
(
)
;
//get line values of the lines
var
x1
=
document
.
getElementById
(
"x1"
)
.
value
;
var
y1
=
document
.
getElementById
(
"y1"
)
.
value
;
var
x2
=
document
.
getElementById
(
"x2"
)
.
value
;
var
y2
=
document
.
getElementById
(
"y2"
)
.
value
;
var
answer
=
getSlopeThatPassedThrough2Points
(
x1
,
y1
,
x2
,
y2
)
;
console
.
log
(
answer
)
;
if
(
x1
.
length
==
0
||
y1
.
length
==
0
||
x2
.
length
==
0
||
y2
.
length
==
0
)
{
window
.
alert
(
"Enter a digit"
)
;
}
else
{
document
.
getElementById
(
"showResult"
)
.
innerHTML
=
answer
;
}
}
/**Main web - Index - Home */
function
SlopeEquation
(
)
{
//rotate the image
rotate
(
)
;
//get line values of the lines
var
x1
=
document
.
getElementById
(
"x1"
)
.
value
;
var
y1
=
document
.
getElementById
(
"y1"
)
.
value
;
var
x2
=
document
.
getElementById
(
"x2"
)
.
value
;
var
y2
=
document
.
getElementById
(
"y2"
)
.
value
;
var
answer
=
getSlopeEquationAsString
(
x1
,
y1
,
generatedEquationSlope
)
;
console
.
log
(
"index"
+
answer
)
;
if
(
x1
.
length
==
0
||
y1
.
length
==
0
||
x2
.
length
==
0
||
y2
.
length
==
0
)
{
window
.
alert
(
"Enter a digit"
)
;
}
else
{
document
.
getElementById
(
"showResult"
)
.
innerHTML
=
answer
;
}
}
/**JS Function level 1 */
//set values 1-10
document
.
getElementById
(
"showPoints"
)
.
innerHTML
=
"("
+
x1
+
" ,"
+
y1
+
") , "
+
"("
+
x2
+
" ,"
+
y2
+
")"
;
function
submitAnswer
(
)
{
//rotate the image
// rotate();
//get line values of the lines
// var answer = getSlopeThatPassedThrough2Points(x1, y1, x2, y2);
var
userAnser
=
document
.
getElementById
(
"userAnswer"
)
.
value
;
if
(
userAnser
==
generatedEquationSlope
)
{
console
.
log
(
"correct"
)
;
document
.
getElementById
(
"answerIcon"
)
.
innerHTML
=
" "
;
document
.
getElementById
(
"answerIcon"
)
.
className
=
"fa fa-check-circle-o"
;
document
.
getElementById
(
"answerIcon"
)
.
style
=
"font-size:48px;color:green"
;
}
else
{
console
.
log
(
"incorrect"
)
;
document
.
getElementById
(
"answerIcon"
)
.
innerHTML
=
" "
;
document
.
getElementById
(
"answerIcon"
)
.
className
=
"fa fa-close"
;
document
.
getElementById
(
"answerIcon"
)
.
style
=
"font-size:48px;color:red"
;
}
// setRotateBack();
}
//this is correct? no ! b is wrong
//html call by id function
function
getEquationFormula
(
)
{
document
.
getElementById
(
"answerIcon"
)
.
innerHTML
=
"m = (y2 - y1) / (x2 - x1)"
+
" <br><br> y="
+
generatedEquationSlope
+
" x + ("
+
bEquation
+
")"
;
document
.
getElementById
(
"answerIcon"
)
.
className
=
" "
;
document
.
getElementById
(
"answerIcon"
)
.
style
=
"font-size:48px;color:black"
;
}
//****Math FORMULAS********//
// get slope formula of two points in the plane or graph
function
getSlopeThatPassedThrough2Points
(
x1
,
y1
,
x2
,
y2
)
{
var
m
;
//m is slope
m
=
(
y2
-
y1
)
/
(
x2
-
x1
)
;
//equation to find m
return
m
;
}
//return a string or the equation
//correct
function
getBFromSlopeEquation
(
)
{
// y = mx - b
var
b
=
y1
;
// var mx;
var
x
=
1
;
//initial equation : y-y1 = m(x-x1)
//1) negate x1 and y1
x1
=
-
1
*
x1
;
y1
=
-
1
*
y1
;
//2) m(x-x1)
mx
=
generatedEquationSlope
*
x
;
b
=
generatedEquationSlope
*
x1
;
//3) find y, by passing y to the other part of the equation
b
=
b
+
(
-
1
*
y1
)
;
b
=
Math
.
round
(
100
*
b
)
/
100
;
return
b
;
}
function
getSlopeEquationAsString
(
)
{
console
.
log
(
x1
+
" "
+
y1
)
;
var
equation
=
""
;
// y = mx - b
var
b
=
y1
;
// var mx;
var
x
=
1
;
//initial equation : y-y1 = m(x-x1)
//1) negate x1 and y1
x1
=
-
1
*
x1
;
y1
=
-
1
*
y1
;
//2) m(x-x1)
mx
=
generatedEquationSlope
*
x
;
b
=
bEquation
;
//end result : y = mx - b , print
if
(
b
>
0
)
{
equation
=
"y = "
+
mx
+
"x + "
+
b
;
}
else
{
equation
=
"y = "
+
mx
+
"x "
+
b
;
}
return
equation
;
}
//****Website Function********//
//rotate Icon
function
rotate
(
)
{
document
.
getElementById
(
"circleImage"
)
.
id
=
"circleByteRotate"
;
//rotate image
console
.
log
(
"id set"
)
;
}
function
setRotateBack
(
)
{
document
.
getElementById
(
"circleByteRotate"
)
.
id
=
"circleImage"
;
console
.
log
(
"id back"
)
;
}
console
.
log
(
"draw this line:"
+
"("
+
x1
+
" ,"
+
y1
+
") , "
+
"("
+
x2
+
" ,"
+
y2
+
")"
)
;
//slope, x and y
myGraph
.
drawEquation
(
function
(
x
)
{
//console.log(getSlopeEquationAsString(x1,x2,generatedEquationSlope));
// console.log("draw line: "+generatedEquationSlope+" " + x + " " +bEquation);
return
(
generatedEquationSlope
*
x
)
+
bEquation
;
}
,
'aqua'
,
3
)
;
Back
|
FazBrowse Home
|
New Git URL