This lesson-quiz represents some 'break-through' thinking:
These quizzes demand interaction. The plan is to create the
equivalent of a classroom discusson on the Web. Added to
this is that you are graded for participating, and hopefully
you will glean information from others that will add to your
understanding and subsequently Mastery over the topics
GLASS BOX Math and String Functions
At the end of the lesson, -- when you know that you understand
it -- say "Mr. A. --
I got this lesson, thank you -- and type your name.
Q001: The script portion is stored in the HEAD section
of the HTML -- Give me as deep an answer as you
has to be in this section, and not the BODY?
(If you dont know, skip it, and come back to it later.)
Translate (explain) this JS statement in English:
var mv = new String(this.document.forms.inputNum.value);
alert("Math.sqrt(" + mv + ") yields " + Math.sqrt(mv));
Displays on screen:
Math.sqrt(123) yields 11.09053678912
Clue: 'alert' displays to screen. The sq rt of 'mv' is taken
and displayed. What do the '+' signs do?
alert("The method 'Math.round.(Math.sqrt(" + mv + ")) yields
" + Math.round(Math.sqrt(mv)*100)/100 + " (rounded).");
that displays as:
The method 'Math.round.(Math.sqrt(123)') yields 11.09 (rounded)
Explain Math.round -- how it works. Explain how it got rounded to 2 dec places.
Should include explanation of how mult and div are used to shift the decimal
position, and how that works with the round() function. (If you dont know,
skip it, and come back later.)
Almost the same as Q004, EXPLAIN THE FOLLOWING
AND WHY IT IS DONE:
alert(vara1+ "= a randomly-generated number between 0 - 1 [2 decimal places]");
EXPLAIN EACH OF THE FOLLOWING LINES:
alert("The sine of PI = approximately 0! -- Try it!");
alert("The sine of " + 3.141692 + " = " + Math.sin(3.141692) + " in radians.") ;
varc = Math.sqrt(mv);
alert("The sqrt of " +mv + " = " +varc + " The sqrt squared = " + Math.pow(varc,2));
alert("The sine of " + mv + " = " + Math.sin(mv));
I HAD TO DO SOME PROGRAMMING TRICKS TO GET ADDITION TO WORK:
GO FIND IT, EXPLAIN IT, AND WHY I HAD TO DO IT THAT WAY:
EXPLAIN THE 'length' function -- how it works, and EXPLAIN
the substr function.
lmv = mv.length;
alert ("lmv = mv.length ");
alert ("The method 'lmv = mv.length' returns length of mv, stored in lmv.");
alert ("The length of " + mv + " = " + mv.length);
alert (mv + ".length" + " = " + lmv);
alert ("Position is counted from 0 position");
mmv = mv.substr(0,1);
Explain each line like this:
1. starts BODY, sets screen background color to yellow.
9 the form characteristics are: it accepts a field called
'inputNum' which is text, length of 8, initialized to null.
I used "Glassbox" approach here contrasted with
"Blackbox" -- Glassbox (GB) means opening up the process
so you can see what is happening inside.
Give an example from this lesson of GB.
Does it help you? Comments.