Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to build a Javascript ternary formula

 
jennifer gisler
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15208
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MDN COnditional Operator

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic