Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Javascript form calculation?

05admay

Coder
Hi Guys,

I need help with this calculation, im designing a form for a client that needs a MAX PRICE between two values. I'm using the javascript below but this makes each quantity 250, I need it so its a maximum of 250 Upto 24999 and then ill do another value between 25000 up to 29999 and the price would be 275.

JavaScript:
if([item-417_quantity]<24999){
  [price]=250
}

I'll appreciate anyone's help, Thanks guys!!
 
If it's like that, they why doesn't this work, have you checked the console for any errors?
JavaScript:
if (quantity < 25000) {         //
  var price = 250 * quantity;   //
} else if (quantity < 30000) {  //  replace quantity and price with your variables
  var price = 275 * quantity;   //
}                               //
Hi Johna,

This is what worked in the end, so I need to attach
JavaScript:
else if
to duplicate the same calculation with different values?

JavaScript:
if ([item-417_quantity] < 25000) {
[price] = 250/[item-417_quantity]
}
 
If it's like that, they why doesn't this work, have you checked the console for any errors?
JavaScript:
if (quantity < 25000) {         //
  var price = 250 * quantity;   //
} else if (quantity < 30000) {  //  replace quantity and price with your variables
  var price = 275 * quantity;   //
}                               //
This is the code that ended up working. that was hard :cry: :Rofl: Thank you very much for all your help JOhna, Really mean that!!

JavaScript:
if ([item-417_quantity] < 25000) {
[price] = 250/[item-417_quantity]
}else if ([item-417_quantity] > 25000) {
[price] = 275/[item-417_quantity]
}
 
This is the code that ended up working. that was hard :cry: :Rofl: Thank you very much for all your help JOhna, Really mean that!!

JavaScript:
if ([item-417_quantity] < 25000) {
[price] = 250/[item-417_quantity]
}else if ([item-417_quantity] > 25000) {
[price] = 275/[item-417_quantity]
}
in the else if it should probably be 30000?:
JavaScript:
else if ([item-417_quantity] > 30000)
 
What is item-417_quantity supposed to be ? That's not a valid identifier name. Look what happens if you paste that in Node.js:

JavaScript:
Welcome to Node.js v16.14.2.
Type ".help" for more information.
> [price] = 250/[item-417_quantity]
[price] = 250/[item-417_quantity]
                        ^
Uncaught SyntaxError: Numeric separators are not allowed at the end of numeric literals

Are you aware of the difference between a hyphen and underscore ?

And what's with all the square brackets anyway ? Why are you using them ? Look what happens in Node.js:

JavaScript:
> [price] = 250
Uncaught:
TypeError: number 250 is not iterable (cannot read property Symbol(Symbol.iterator))

With normal JS in a webpage I would expect you to get the same kind of errors in the Console log. Did you look there ?

As to your last question, if you use 30000 in the else if you are missing out on values 25000..30000. Surely that cannot be your intention ? In your original code (assuming it would work) you were only missing out on value 25000.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom