mercredi 10 février 2021

Return a number that is not too small and not too big to use for operation?

I need help writing some javascript logic for a function that takes in an argument, num then declares the variables within the function:

const N = 21; 
const otherN = ( some logic );
const sum = ( N * otherN ) - num = some number greater than 21.

I’m wanting to write logic that will give me some number for my const otherN that I can use to run the operation, sum, with num, so that when N * otherN is subtracted from num, the sum wouldn’t be less than N BUT some number closer to N.

The desired output would be:

num = 288;
N = 24; 
otherN = (some logic ) ; // otherN chosen, 10

const sum = ( N * otherN ) - num = 48; // sum equals 48

An undesired output would be:

num = 288;
N = 24; 
otherN = (some logic ) ; // otherN chosen, 124

const sum = ( N * otherN ) - num = 48; // sum equals -2688

Hopefully, this makes sense. I imagine the otherN would also have to NOT be greater than num so there would be a condition of < num, but the otherN couldn't be something too large like if num was 200, otherN could NOT be 199.

Aucun commentaire:

Enregistrer un commentaire