Skip to content

Commit

Permalink
Fix the scoping problem of the buttonable function.
Browse files Browse the repository at this point in the history
  • Loading branch information
atom-box committed Sep 4, 2021
1 parent a631d27 commit 620495a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 12 deletions.
10 changes: 10 additions & 0 deletions data/quiltData.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
console.log('start quiltdata.');


/*****
Don't arbitrarily edit the title!
It is important that you use the same string for the following three things:
TITLE & javascriptfile & the id of the div for inserting the solution code
For example, if the title is maxEnd3, the file is maxEnd3.mjs and the div will be <div id="maxEnd"></div>
******/
let articles = [
{
backgroundColor: '#493',
textColor: '#ddf',
title: 'Hotdogging',
question: 'How do you grab a div?',
strategy: 'GetElementById()!',
form: '<form><h1>Placeholder</h1><button>click</button></form>',
Expand All @@ -15,6 +24,7 @@ let articles = [
{
backgroundColor: '#256',
textColor: '#db5',
title: 'maxEnd3',
question: 'Given an array of ints length 3, figure out which is larger, the first or last element in the array, and set all the other elements to be that value. Return the changed array.',
strategy: 'GetElementById()!',
form: '<form><h1>Placeholder</h1><button>click</button></form>',
Expand Down
16 changes: 16 additions & 0 deletions helpers/quilt/maxEnd3.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
window.addEventListener('DOMContentLoaded', (event) => {
// const btn = document.getElementById('maxEnd3Button');
// btn.addEventListener('click', alert('whipping'));
let dice = {};

dice.roll5 = function() {
return Math.ceil(5 * Math.random());
}

dice.show5 = function() {
// dice.el = document.getElementById('diceout');
dice.el.innerHTML = dice.roll5();
dice.el.style = `color: blue;`
}

});
14 changes: 14 additions & 0 deletions helpers/quilt/maxEnd3Div.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
document.addEventListener('DOMContentLoaded', (event) => {

let anchor = document.getElementById('maxEnd3');
let webform = `
<h3>Notice the distribution of results as you repeatedly roll a dice with sides of</h3>
<div class="btn-group">
<button type="button" class="btn btn-primary btn-sm" onclick="dice.show5()" > five</button>
<button type="button" class="btn btn-danger btn-sm" onclick="dice.show7()" > seven</button>
</div>
<h3 id="diceout" style="color:transparent">null 99</h3>
`;
anchor.innerHTML = webform;
});
1 change: 1 addition & 0 deletions helpers/quilt/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return("we hit a succesful test");
7 changes: 5 additions & 2 deletions helpers/quiltMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ singleDiv = '';
articles.forEach(element => {

singleDiv = `<article style="background-color:${element.backgroundColor}; color: ${element.textColor};"><div class='gutters';>
<h2 >How\'s this?</h2>
<p>The background-color is: ${element.backgroundColor}</p></div>
<h2 >${element.title}</h2>
<p>Challenge description: ${element.question}</p></div>
`;

singleDiv += `<div id="${element.title}">`;

singleDiv += `
</article>
`;
Expand Down
31 changes: 21 additions & 10 deletions quilt.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

/* For tablets: */
.gutters {
padding-left: 9rem;
padding-right: 9rem;
padding-left: 9rem;
padding-right: 9rem;
}
}

@media only screen and (min-width: 1000px) {
.gutters {
padding-left: 19rem;
padding-right: 19rem;
padding-left: 19rem;
padding-right: 19rem;
}
}

Expand Down Expand Up @@ -111,10 +111,17 @@
}
</style>


<script src="./data/quiltData.mjs"></script>
<script src="./helpers/quiltMain.js"></script>

<script>
let dice = {};
dice.roll5 = function() {
return Math.ceil(5 * Math.random());
}

dice.show5 = function() {
// dice.el = document.getElementById('diceout');
console.log( dice.roll5());
}
</script>
</head>


Expand All @@ -127,12 +134,11 @@ <h1>Let's Go:</h1>
<p>Write Javascript!<br>Sharpen the edge!<br>Timebox these activities!</p>
</div>
</div>
<div class="cleared"></div>
</div>
</header>

<article>
<p id="articlesAnchor">lou</p>
<p id="articlesAnchor">Install Javascript for proper display.</p>
</article>

<footer class="card">
Expand All @@ -153,6 +159,11 @@ <h2 class="text-right gutters">Making things in Madison, Wisconsin: <span class=

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="./data/quiltData.mjs"></script>
<script src="./helpers/quiltMain.js"></script>
<script src="./helpers/quilt/maxEnd3.mjs"></script>
<script src="./helpers/quilt/maxEnd3Div.mjs"></script>


</body>

Expand Down

0 comments on commit 620495a

Please sign in to comment.