Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cube-root-training
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kevin Lyda
cube-root-training
Commits
00a89f94
Commit
00a89f94
authored
7 years ago
by
Kevin Lyda
Browse files
Options
Downloads
Patches
Plain Diff
JS version.
parent
e07cf2b0
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
index.html
+74
-0
74 additions, 0 deletions
index.html
with
74 additions
and
0 deletions
index.html
0 → 100644
+
74
−
0
View file @
00a89f94
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
/>
<title>
Cube Root Training
</title>
</head>
<body>
<h1>
Cube Root Training
</h1>
<p
id=
cube
></p>
<p><input
type=
"text"
id=
"cuberoot"
value =
""
size=
3
></p>
<p
id=
result
></p>
<p
id=
stats
></p>
<script>
var
cube
=
document
.
getElementById
(
"
cube
"
);
var
cuberoot
=
document
.
getElementById
(
"
cuberoot
"
);
var
result
=
document
.
getElementById
(
"
result
"
);
var
stats
=
document
.
getElementById
(
"
stats
"
);
var
began
;
var
finished
;
var
elapsed
=
0
;
var
generated
;
var
guesses
=
0
;
var
correct
=
0
;
cuberoot
.
addEventListener
(
"
keydown
"
,
function
(
e
)
{
if
(
e
.
keyCode
===
13
)
{
check_cuberoot
(
e
);
}
})
function
humanize_ms
(
ms
)
{
if
(
ms
<
1000
)
{
return
ms
+
"
ms
"
;
}
else
{
return
(
Math
.
floor
(
ms
/
100
)
/
10
)
+
"
s
"
;
}
}
function
start_round
()
{
if
(
guesses
>
0
)
{
stats
.
innerHTML
=
"
Got
"
+
correct
+
"
correct out of
"
+
guesses
+
"
. Last round took
"
+
humanize_ms
(
finished
-
began
)
+
"
.
"
+
((
correct
>
0
)
?
"
Average time of correct guess was
"
+
humanize_ms
(
elapsed
/
correct
)
+
"
.
"
:
""
);
}
generated
=
Math
.
floor
(
Math
.
random
()
*
90
)
+
10
;
cube
.
innerHTML
=
Math
.
pow
(
generated
,
3
);
began
=
Date
.
now
();
cuberoot
.
value
=
""
;
cuberoot
.
focus
();
}
function
check_cuberoot
(
e
)
{
var
guess
=
e
.
target
.
value
;
guesses
++
;
finished
=
Date
.
now
();
if
(
guess
==
generated
)
{
correct
++
;
elapsed
+=
(
finished
-
began
);
result
.
innerHTML
=
"
Correct!
"
;
}
else
{
result
.
innerHTML
=
"
Not correct! Correct answer was
"
+
generated
+
"
.
"
;
}
start_round
();
}
start_round
();
</script>
</body>
</html>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment