File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes How to build a Javascript ternary formula Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to build a Javascript ternary formula" Watch "How to build a Javascript ternary formula" New topic

How to build a Javascript ternary formula

jennifer gisler

Joined: Jul 17, 2013
Posts: 1

First I just want to say thank you for taking the time to read this and to let you know I am a total beginner Javascript coder.

I am trying to write the following formula in ternary format and any help and/or suggestions would be great.

I am using ternary because I am building a calculator and the plugin that I found will only work with ternary expressions. If you know how or have suggestions on how to make this calculator work differently, again that would be great.

So here is the basic idea...

If Resident = true then
percredite = 829
percredit = 1078

If credits < 6 then
total = credits * percredit
Elseif credits >6 and <15 then
total = 7500 * ((credits - 15) * percredit)
total = 7500
End If

So if the user selects resident the percredit amount is 829 otherwise it is 1078.

Hopefully this makes sense.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

Welcome to the Ranch.

That's not JavaScript code. Did you intend it to be pseudo-code, or do you have your languages mixed up?

[Asking smart questions] [About Bear] [Books by Bear]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15082

Welcome to the Ranch.

Java or JavaScript? Those are two different languages - even though they both have "Java" in their name, they really don't have a lot to do with each other.

We do have a forum about JavaScript here, so I'll move your question over there.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
MDN COnditional Operator

I agree. Here's the link:
subject: How to build a Javascript ternary formula
It's not a secret anymore!