Get your CodeRanch badge!*
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
Author

How to build a Javascript ternary formula

jennifer gisler
Greenhorn

Joined: Jul 17, 2013
Posts: 1
Hi,

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
Else
percredit = 1078
EndIf

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

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

Hopefully this makes sense.

Thanks,
Jen
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13881
    
  10

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 7 API documentation
Scala Notes - My blog about Scala
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
MDN COnditional Operator

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to build a Javascript ternary formula
 
Similar Threads
Efficient way to calculate the number of threads
calculating form fields
Application design for rapidly changing formulae
Breaking objects (logic puzzle, no OOP)
Alternative to if else block