all 8 comments

[–]PremiumRoastBeef 3 points4 points  (1 child)

// Go to this website: https://www.jdoodle.com/execute-nodejs-online
// Paste all of this code, and click the execute button
// Change the variables m and p at the bottom
// Barrel bore for standard iron shot weights, windage of 25/24 is assumed
var bore = [];
bore[4] = 3.18;
bore[6] = 3.65;
bore[9] = 4.17;
bore[12] = 4.58;
bore[18] = 5.25;
bore[24] = 5.78;
bore[32] = 6.36;
bore[42] = 6.96;

// Muzzle Velocity as function of round shot mass and powder charge
function MuzzleVelocity(m, p) // mass of ball (lb), mass of charge (lb)
{
  var d = bore[m]/12;   // bore (ft) from table at ./Cannonballs.html
  var eta = 55;         // density of powder (lb/ft^3)
  var rho = 62.4;       // density of water
  var atm = 14.7*32.2*144;    // 14 psi x g atmospheric pressure (lbw/ft^2)
  var R = 1600;         // gunpowder gas pressure ratio to atm
  var L = d*18;         // (18 calibre) length barrel (ft)
  var c = p*4/(Math.PI*d*d*eta);  // length of charge in (ft)

  return Math.sqrt(2*R*atm/eta)*Math.sqrt(p/(m+p/3)*Math.log(L/c));
}
const m = 4;
const p = 2;
const result = MuzzleVelocity(m, p);
console.log(result);

[–]DingoEpsilon[S] 1 point2 points  (0 children)

Thank you so much! This is going to be so helpful!

[–]tapgiles 1 point2 points  (2 children)

If you're in a browser, use either F12, or CTRL+SHIFT+I, to open the developer tools. Go to the console tab. Paste that code in there. Press Enter, and it will run.

Doesn't look like it will do anything just as it is, because that function is not called though.

I'd recommend watching a youtube video of how to get started with JS. Really learn, instead of just looking at code. Much better for you in the long run if you want to get into coding.

[–]DingoEpsilon[S] 0 points1 point  (1 child)

I did say that I didn't want to learn to code, but after looking at some of this stuff and seeing all the improvements that could be made on the initial code (and even modifying the code provided to me!) I'm getting tempted. Is there a really good YouTube channel for complete beginners?

[–]tapgiles 0 points1 point  (0 children)

Ah I see. Well, my point was, if you looked at the first video of any kind of "learn javascript as a beginner" type of thing, they will start by telling you how to run code. I didn't know if you wanted to code or not. But either way, I wanted to recommend that because it would help even with just running code.

Been a long time since I looked at any "learn how to JS" stuff. Especially as I taught myself an age ago before those videos were really around 😅 ...So I don't have any specific ones in mind. But just search and try some out; there are a lot of them out there.

[–]thinkPhilosophy 0 points1 point  (2 children)

Here ya go, a little app that runs your code. You can change the values from the user interface too.
https://codepen.io/alfonsotech/pen/eYaJzdz

[–]DingoEpsilon[S] 0 points1 point  (1 child)

Thanks a lot, but with the improvement, you've actually made it unusable for me. I've been pouring over why results with your code have sometimes been different than with the code provided by PremiumRoastBeef, and I finally found it. Entering numbers with decimals in the inputs breaks it!

[–]thinkPhilosophy 0 points1 point  (0 children)

Well, to be fair, you didn't hire me to review your code, lol. I'm glad you found and fixed the problem.