The previous Body Systems Quiz Game Primer Tutorial shares many commonalities with todayโs Respiratory System quiz, two major commonalities being โฆ
- the source for the quiz knowledge โฆ thanks to HLTAAP001 Recognise healthy body systems TAFE NSW
- both quizzes have a single image as a reference point but neither use (or need) HTML map nor canvas elements
โฆ and today, for the first time that we can remember we set our image as the background image to an HTML โฆ
- form element โฆ
- action=[hereโsLookingAtYouKid]
- method=GET
- style=โwidth:640px;height:480px;background: URL(respiratory_system.jpg) no-repeat;โ
- comprised of input type=text textboxes and one type=submit button overlayed into specific positions masking the image at points where that image would have given the answer away, as per โฆ
<input placeholder='What is this?' type=text style='position:absolute;left:108px;top:142px;' name=fld1 id=fld1 value=''></input>
<input placeholder='What is this?' type=text style='position:absolute;left:458px;top:108px;' name=fld2 id=fld2 value=''></input>
<input placeholder='What is this?' type=text style='position:absolute;left:458px;top:158px;' name=fld3 id=fld3 value=''></input>
<input placeholder='What is this?' type=text style='position:absolute;left:458px;top:223px;' name=fld4 id=fld4 value=''></input>
<input placeholder='What is this?' type=text style='position:absolute;left:458px;top:312px;' name=fld5 id=fld5 value=''></input>
<input placeholder='What is this?' type=text style='position:absolute;left:458px;top:410px;' name=fld6 id=fld6 value=''></input>
<input id='sb' type=submit style='background-color:yellow;position:absolute;left:458px;top:460px;' value='Check Answers'></input>
โฆ and this is where you may have cried out โHow did you get good values for top and left positions, given you are not using an HTML map element?โ. Well, we temporarily put the flowchartbits you can further read about at Flowchart Colours Tutorial (and our own bits, temporarily) โฆ
function recxy(event) {
var isok=true;
//if (document.getElementById('dpf')) {
// if (('' + document.getElementById('dpf').style.display).toLowerCase().indexOf('block') != -1) { alert('cliCk ' + wording + ' ' + bodyclick); }
//}
if (event.touches) { // thanks to https://stackoverflow.com/questions/24567441/how-do-i-detect-two-fingers-at-touchstart-in-javascript
if (event.touches.length > 1) { isok=false; }
}
if (isok) {
if (x == 0 && y == 0 && lastx == 0 && lasty == 0) {
if (event.clientX || event.clientY) {
x = event.clientX; // - elemLeft;
y = event.clientY; // - elemTop;
} else {
x = event.pageX; // - elemLeft;
y = event.pageY; // - elemTop;
}
lastx=x;
lasty=y;
//if (document.getElementById('dpf')) {
// if (('' + document.getElementById('dpf').style.display).toLowerCase().indexOf('block') != -1) { alert('Click ' + wording + ' ' + bodyclick); }
//}
setTimeout(xthen, 2000);
setTimeout(andthen, 1000);
} else {
if (event.clientX || event.clientY) {
if (x != event.clientX || y != event.clientY) {
lastx=x;
lasty=y;
//if (document.getElementById('dpf')) {
// if (('' + document.getElementById('dpf').style.display).toLowerCase().indexOf('block') != -1) { alert('ClIck ' + wording + ' ' + bodyclick); }
//}
setTimeout(xthen, 2000);
setTimeout(andthen, 1000);
//} else {
//document.title+=' ! ';
}
} else {
if (x != event.pageX || y != event.pageY) {
lastx=x;
lasty=y;
//if (document.getElementById('dpf')) {
// if (('' + document.getElementById('dpf').style.display).toLowerCase().indexOf('block') != -1) { alert('clicK ' + wording + ' ' + bodyclick); }
//}
setTimeout(xthen, 2000);
setTimeout(andthen, 1000);
//} else {
//document.title+=' ? ';
}
}
if (event.clientX || event.clientY) {
x = event.clientX; // - elemLeft;
y = event.clientY; // - elemTop;
} else {
x = event.pageX; // - elemLeft;
y = event.pageY; // - elemTop;
}
}
//alert('x=' + x + ' and y=' + y);
}
alert('x=' + x + ' and y=' + y);
}
</script>
</head>
<body onclick='recxy(event);' onload='checkanswers();' style='background-color:yellow;'>
โฆ just for the period writing the web application, and then we ended up with this very pared back respiratory_systemhtml with its associated live
run link for you to test out your Respiratory System knowledge.
Previous relevant Body Systems Quiz Game Primer Tutorial is shown below.
โRegionalโ click (or touch) web application functionality doesnโt have to be always done via an HTML map element thangthing. Today, as an alternative methodology, we โฆ
- start with a useful โBody Systemsโ image โฆ thanks to HLTAAP001 Recognise healthy body systems TAFE NSW
- set it up as the document.body background: url(โbody_systems.jpgโ) no-repeat; background image
- โoverlayโ a โฆ
โฆ HTML table element โgridโ on top
- add HTML table elementโs cellsโ onclick event logics that work on the scoring for the โBody Systems Quizโ game we have for you today
- an HTML select โdropdownโ element gets randomly selected with a โBody Partโ for which the user then (and features the use of data attributes to store associated data items) โฆ
- clicks (or touches) (a โBody Systemโ arrowhead representing) one of the HTML table elementโs cells (but looks to the user as the original background image showing โBody Systemsโ), triggering the scoring analysis logic for todayโs โBody
Systems (of Body Parts) Gameโ whose HTML and Javascript and bit of CSS source code body_systems
html is there for your perusal
You may wonder, from this, whereโs the relationship among โฆ
- Body System
- Body Part
- Grid Reference (ie. HTML table elementโs cellsโ IDs)
โฆ established? Again, as you may be really sick of by now with us, nothing more complicated data structure wise, than a โBody System:Body Parts List (comma separated):Grid Reference List (comma separated)โ array, as exemplified by the snippet โฆ
var b_s=["Cardiovascular:heart,blood,vessels:3_2,3_3,5_2",
...
];
When taking a look at todayโs HTML and Javascript and bit of CSS source code body_systemshtml you may notice โthe bit of CSSโ, literally โฆ
<style>
td { width: 10%; height: 10%; border: 0px inset red; }
</style>
โฆ and wonder, whatโs the go with the 0px bit of โborder: 0px inset red;โ? Well, itโs a reminder back to how we โdebuggedโ the โGrid Referenceโ array data we collected. When developing this web application, we had, for debugging purposes, this CSS as โฆ
<style>
td { width: 10%; height: 10%; border: 1px inset red; }
</style>
โฆ and just during that period we had a way to tell in which HTML table elementโs cell a โBody Systemโ arrowhead would fall. It may not be to your liking to leave such โkludgesโ in live code, and often weโd agree, but if something is such an obvious code โattention seekerโ, we actually find leaving such โpeccadillosโ in instructive into future revisits of such code.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.