Commit a08727e8 by Trevor Austin

Add in-class lab examples

parent 212fa65e
<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>
<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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment