Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Trevor Austin
/
mpcs-52553-austin-winter-2021
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a08727e8
authored
Feb 10, 2021
by
Trevor Austin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add in-class lab examples
parent
212fa65e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
0 deletions
week_5/examples/randomWalk.html
week_5/examples/setTimeout.html
week_5/examples/randomWalk.html
0 → 100644
View file @
a08727e8
<meta
content=
"text/html;charset=utf-8"
http-equiv=
"Content-Type"
>
<meta
content=
"utf-8"
http-equiv=
"encoding"
>
<html>
<head>
<title>
Random Concept Walk
</title>
</head>
<body>
<h3>
Take a random walk though concept space
</h3>
<small>
Powered by Bing™
</small>
<div>
<input
id=
"input"
></input>
<button
id=
"walk"
value=
"Walk!"
>
Walk!
</button>
</div>
<script>
let
input
=
document
.
getElementById
(
"input"
);
let
button
=
document
.
getElementById
(
"walk"
);
function
getRelatedConcept
(
seed
){
let
bing
=
"https://api.bing.microsoft.com/v7.0/images/search?q="
let
walkHeaders
=
new
Headers
();
walkHeaders
.
append
(
"Ocp-Apim-Subscription-Key"
,
"683a963608f14d42b8cceda2a96c94cf"
);
walkHeaders
.
append
(
"Accept"
,
"application/json"
);
walkHeaders
.
append
(
"Accept"
,
'application/json'
);
const
myInit
=
{
method
:
'GET'
,
headers
:
walkHeaders
,
};
console
.
log
(
"Searching: "
+
seed
);
let
search
=
fetch
(
bing
+
seed
,
myInit
);
return
search
.
then
(
function
(
response
)
{
return
response
.
json
();
}).
then
(
function
(
json
)
{
related
=
json
[
'relatedSearches'
]
randomRelated
=
related
[
Math
.
floor
(
Math
.
random
()
*
related
.
length
)][
'text'
];
console
.
log
(
randomRelated
);
return
randomRelated
;
});
}
button
.
addEventListener
(
"click"
,
function
()
{
let
seed
=
input
.
value
;
console
.
log
(
seed
);
getRelatedConcept
(
seed
).
then
(
function
(
response
){
return
getRelatedConcept
(
response
);
}).
then
(
function
(
response
){
return
getRelatedConcept
(
response
);
}).
then
(
function
(
response
){
return
getRelatedConcept
(
response
);
}).
then
(
function
(
response
){
return
getRelatedConcept
(
response
);
}).
then
(
function
(
response
){
return
getRelatedConcept
(
response
);
});
});
</script>
</body>
</html>
week_5/examples/setTimeout.html
0 → 100644
View file @
a08727e8
<meta
content=
"text/html;charset=utf-8"
http-equiv=
"Content-Type"
>
<meta
content=
"utf-8"
http-equiv=
"encoding"
>
<html>
<head>
<title>
setTimeout Example
</title>
</head>
<body>
<input
id=
"delayInput"
></input>
<button
id=
"setTimer"
value=
"Set Timer"
>
Set Timer
</button>
<script>
let
input
=
document
.
getElementById
(
"delayInput"
);
let
button
=
document
.
getElementById
(
"setTimer"
);
button
.
addEventListener
(
"click"
,
function
()
{
setTimeout
(
function
(){
console
.
log
(
"Ding!"
)
},
input
.
value
*
1000
);
});
let
myGreeting
=
setTimeout
(
function
()
{
console
.
log
(
'Hello!'
);
},
0
)
console
.
log
(
'Howdy!'
);
</script>
</body>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment