Amado
12/06/2022, 5:36 PM<cfscript>
function computeQuadratic(a,b,c) {
var discriminant1 = (-1 * b) + sqr((b*b) -(4*a*c));
var discriminant2 = (-1 * b) - sqr((b*b)-(4*a*c));
var root1 = discriminant1/(2*a)
var root2 = discriminant2/(2*a)
writeOutput ("<p> the answer for root1 is #root1#</p>");
writeOutput ("<p> the answer for root2 is #root2#</p>");
} computeQuadratic(3,8,4);
Adam Cameron
<http://localhost/some/path/someFile.cfm>
and it... works?Adam Cameron
Adam Cameron
Adam Cameron
Amado
12/06/2022, 5:46 PMAmado
12/06/2022, 5:50 PMAdam Cameron
Adam Cameron
Scott Steinbeck
12/06/2022, 5:53 PM<cfdump var=#form#>
<form action="index.cfm" method="post">
<div> Quadratic Formula Calculator</div>
<div class="calculatorInputs">
ax^2 + bx + c = 0
<div>
<label for="a">a =</label>
<input name="a" id="a" value="1">
</div>
<div>
<label for="b">b =</label>
<input name="b" id="b" value="2">
</div>
<div>
<label for="c">c =</label>
<input name="c" id="c" value="3">
</div>
</div>
<input type="submit" value="Calculate" >
</form>
NOTE: this code works because you are creating it as an index.cfm
page and the form action
is submitting the form to the index.cfm
pageScott Steinbeck
12/06/2022, 5:54 PM<cfdump var="#form#">
is taking the user input in the HTML form once its submitted and allowing you to use it in coldfusion via the form
scopeAdam Cameron
Adam Cameron
Mark Takata (Adobe)
12/06/2022, 5:55 PMAdam Cameron
Adam Cameron
Amado
12/06/2022, 5:57 PMAdam Cameron
Amado
12/06/2022, 6:04 PMAdam Cameron
bdw429s
12/06/2022, 6:22 PMbdw429s
12/06/2022, 6:24 PMtask create --open
and just put your code in the run()
method
component {
function run(
required a,
required b,
required c
) {
var discriminant1 = (-1 * b) + sqr((b*b) -(4*a*c));
var discriminant2 = (-1 * b) - sqr((b*b)-(4*a*c));
var root1 = discriminant1/(2*a)
var root2 = discriminant2/(2*a)
print.line("the answer for root1 is #root1#");
print.line("the answer for root2 is #root2#");
}
}
now run it like
❯ task run :a=1 :b=50 :c=100
the answer for root1 is -2.087121525221
the answer for root2 is -47.912878474779
OR just type
task run
and it will prompt you for the required values!
❯ task run
Enter a :1
Enter b :50
Enter c :100
the answer for root1 is -2.087121525221
the answer for root2 is -47.912878474779
bdw429s
12/06/2022, 6:24 PMAmado
12/06/2022, 6:34 PMAmado
12/06/2022, 6:37 PMAdam Cameron