Multiple Outputs

Home Up Java Script 1 thru 7 
This Page Format is Obsolete!  Go to new site :

This Site will go away in spring of 2016:  Please visit to see NEW SITE!


Java Script 1 thru 7

series 2 pure


Multiple Outputs

The Script below generates multiple outputs. It calculates resistance in parallel, Inductance in parallel and Capacitance in series.  Copy program below using notepad and than make a run time (html) version as you did in previous lesson . You can use this program to make calculate only capacitance for example and ignore outputs for resistance and inductance.  You can read annotation included in program to better understand it.



Copy  text below from HTML tag to HTML tag. 



var Rt; var R1 = 1e-36;var R2 = 1e3;var R3 = 1e3;var R4 = 1000
var recipRt

var Lt; var L1 = .001;var L2 = 1e-3;var L3 = 1.0e-3;var L4 = .001
var recipLt

var Ct; var C1 = 1e-6;var C2 = 1e-6;var C3 = .000001;var C4 = 1.0e-6
var recipCt

var clr = "" // global
var Alpha = "" // global 

function mathgeneral(){
recipRt = 1/R1 + 1/R2 + 1/R3 + 1/R4;
Rt = 1/recipRt;
recipLt = 1/L1 + 1/L2 + 1/L3 + 1/L4;
Lt = 1/recipLt;
recipCt = 1/C1 + 1/C2 + 1/C3 + 1/C4;
Ct = 1/recipCt;
Alpha = ("Rtotal is "+ Rt +"\r" + "Ltotal is " + Lt + "\r" + "Ctotal is "+ Ct);
document.B1.S1.value = Alpha}

<p align="center">
<b><font size="5" color="#808000">Template#2 (R,L,or C in Parallel)</font></b>
<form name="B1">
<p align="center"><input type="button" value="RUN" name="B1" onclick="mathgeneral();"><br>
<p align="center"><textarea rows="6" name="S1" cols="68"></textarea>
<p align="center">&nbsp;
<p align="center"><input type="button" value="Clear Output" name="B2" onclick = "document.B1.S1.value = clr">

<p align="center">

<p align="center"><b><i><font size="2" face="Arial">End of Script</font></i><font face="Arial" color="#808000" size="4"><br>
Directions</font></b><font face="Arial" color="#808000" size="4"><b><br>
Click run button.&nbsp; </b>Program calculates Rtotal for 4 resistors in
parallel, Ltotal for 4 inductors in parallel, and Ctotal for 4 capacitors in
<p align="left"><font face="Arial" color="#808000" size="4"><b>MODIFY COMPONENT
VALUES:&nbsp; </b>View source code and notice that I declared and set values for
resistance, inductance and capacitance using &quot;var&quot;.&nbsp; Since I dealt with
resistance in Template 1, I set R1 to what is effectively a short&nbsp; forcing
Rt to a short. A e-36 simply my way flagging resistance as an irrelevant
results.&nbsp; I could have modified code to avoid any mention of resistance but
I did not want generate a different revision of script for every situation. I
used e-36 ( 10 to the -36 power) rather than zero to avoid dividing by
zero.&nbsp; Dividing by zero will make many computers go into endless loops and
time out.&nbsp; JavaScript allows division by zero and yields a result of
infinity.&nbsp; This reflects a software engineering requirement that the
Internet must go on rather than a hardware break through in binary
<p align="left"><font face="Arial" color="#808000" size="4"><b>Graphical User
Interface (GUI):</b> I have
added a scrolling textbox in place of a single line textbox. This provides you
with a place to output results in any format you desire.</font></p>
<p align="left"><font face="Arial" color="#808000" size="4"><b>Formatting text
output:</b> Lets examine the Script&nbsp; </font><font color="#800000" face="Arial" size="3">Alpha
= (&quot;Rtotal is &quot;+ Rt +&quot;\r&quot; + &quot;Ltotal is &quot; + Lt +
&quot;\r&quot; + &quot;Ctotal is &quot;+ Ct);</font><font color="#800000" face="Arial" size="2"><br>
</font><font face="Arial" size="4"><font color="#808000">The </font><font color="#800000"> Alpha</font><font color="#808000"> string
variable is assigned a string consisting of strings in quotation marks and
variables.&nbsp; </font><font color="#800000"><b>\r</b></font><font face="Arial" color="#808000" size="4">
</font><font color="#808000">
is a carriage return. The</font><font face="Arial" color="#808000" size="4">
</font><font color="#800000"><b>+ </b> </font><font face="Arial" color="#808000" size="4">combines </font><font color="#808000">
all the string and variables into one string variable. Without </font><font color="#800000"><b>\r</b>
</font><font color="#808000">the whole string would be displayed as one long
line of text.</font></font></p>
<p align="left">&nbsp;</p>
<p align="left"><font color="#808000" face="Arial Black" size="4">Outside:
<p align="left"><b><a href=""></a></b></p>
<p align="left">Go to above site and read <b><i>Variables and Data Types</i></b></p>
<p align="left">Go to above site and read <b><i>Operators</i></b></p>
<p align="left">&nbsp;</p>

Copy  text above from HTML tag to HTML tag. 


Questions or problems regarding this web site should be directed to

Copyright ©2003 Science Ebooks All rights reserved.
Last modified: Monday January 18, 2016.