Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Studying LC JavaScript Challenge

Avatar

Level 3

While I'm studying LC JavaScript I took a challenge to translate a web calculator code to LC code.

The web code is listed below.

I was succeful in translating most of it except the essantial. which is the result of the calculation.

I thought I could use the Math function, but no go.

Anyone is intrested in helping out?

<FORM NAME="Calc">
<TABLE BORDER=4>
<TR>
<TD>
<INPUT TYPE="text" NAME="Input" Size="16">
<br>
</TD>
</TR>
<TR>
<TD>
<INPUT TYPE="button" NAME="one" VALUE=" 1 " OnClick="Calc.Input.value += '1'">
<INPUT TYPE="button" NAME="two" VALUE=" 2 " OnCLick="Calc.Input.value += '2'">
<INPUT TYPE="button" NAME="three" VALUE=" 3 " OnClick="Calc.Input.value += '3'">
<INPUT TYPE="button" NAME="plus" VALUE=" + " OnClick="Calc.Input.value += ' + '">
<br>
<INPUT TYPE="button" NAME="four" VALUE=" 4 " OnClick="Calc.Input.value += '4'">
<INPUT TYPE="button" NAME="five" VALUE=" 5 " OnCLick="Calc.Input.value += '5'">
<INPUT TYPE="button" NAME="six" VALUE=" 6 " OnClick="Calc.Input.value += '6'">
<INPUT TYPE="button" NAME="minus" VALUE=" - " OnClick="Calc.Input.value += ' - '">
<br>
<INPUT TYPE="button" NAME="seven" VALUE=" 7 " OnClick="Calc.Input.value += '7'">
<INPUT TYPE="button" NAME="eight" VALUE=" 8 " OnCLick="Calc.Input.value += '8'">
<INPUT TYPE="button" NAME="nine" VALUE=" 9 " OnClick="Calc.Input.value += '9'">
<INPUT TYPE="button" NAME="times" VALUE=" x " OnClick="Calc.Input.value += ' * '">
<br>
<INPUT TYPE="button" NAME="clear" VALUE=" c " OnClick="Calc.Input.value = ''">
<INPUT TYPE="button" NAME="zero" VALUE=" 0 " OnClick="Calc.Input.value += '0'">
<INPUT TYPE="button" NAME="DoIt" VALUE=" = " OnClick="Calc.Input.value = eval(Calc.Input.value)">
<INPUT TYPE="button" NAME="div" VALUE=" / " OnClick="Calc.Input.value += ' / '">
<br>
</TD>
</TR>
</TABLE>
</FORM>

<p align="center"><font face="arial" size="-2">This free script provided by</font><br>
<font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
Kit</a></font></p>

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Agreed. I added a decimal.

p.png

Steve

View solution in original post

9 Replies

Avatar

Former Community Member

There is an eval function in FormCalc that provides the same functionality.

I built a calculator that looks like this...

p.png

If you would like the form, please send a request to stwalker.adobe@gmail.com.

Steve

Avatar

Level 3

Thanks Sreve that would be great.

I did send you a request

Avatar

Level 3

Thanks for sending the for.

How do you solve the number with decimal.

Since there's no % the equation to calculate percentage requires the decimal point. Don't you agree?

Avatar

Correct answer by
Former Community Member

Agreed. I added a decimal.

p.png

Steve

Avatar

Level 3

Thanks Steve,

I have button on the form. I want when the button is pressed to display your calculator and when I press the close button to hide it.

Would you help me out o achieve that?

Avatar

Level 3

Thanks a million!!!

How did you manage to upload a file?

Avatar

Former Community Member

The attach feature is back after being disabled for a while. The site was enhanced to deal with future attacks by viral uploads.

Steve

Avatar

Level 3

I didn't know, so I've uploaded a form to your gmail. I couldn't figure out how to place your calculator into it.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----