0

Determine and print the smallest and largest values contained in 99-element floating-point array. Using notepad++, it doesn't give any errors. If something is wrong, it just won't show anything. This is what I have, but obviously not right. Any suggestions please?

var w = new Array ( 99 );

parseFloat (smallest) = 0;

parseFloat (largest) = 0;

for ( int i = 0; i , 99; ++i )

{

    if w[i] < smallest
       smallest = w[i];
    if w[i] > largest
       largest = w[i];
}

document.writeln( "The smallest number is: " + smallest);

document.writeln( "The largest number is: " + largest);
David Thomas
  • 249,100
  • 51
  • 377
  • 410
  • 1
    What do you intend for `parseFloat (smallest) = 0` to do? – ruakh Mar 07 '15 at 05:48
  • 2
    You've created an array with 50 elements, but all of them are, so far, `undefined`. – David Thomas Mar 07 '15 at 05:50
  • is this wrong : `for ( int i = 0; i , 99; ++i )`; try this : `for ( int i = 0; i < 99; ++i )` – Vikrant Mar 07 '15 at 05:52
  • I was trying to make it read as a number instead of a string so it can be compared. I am not sure about this floating point. That means that decimals can be read correct? How do I only have 50 elements? Please elaborate? & I'm sure they are undefined, not exactly sure how to do it without typing in 99 random numbers. I meant for it to be <, oops. – Rebecca Richardson Mar 07 '15 at 05:54
  • should be using var instead of int: `for ( var i = 0; i < 99; ++i )` – HandyDan Mar 07 '15 at 05:55
  • So the question you're trying to ask is: "*how do I find the minimum, and maximum, numbers from the array of numbers?*" – David Thomas Mar 07 '15 at 05:59
  • You'd have errors in your browser console or wherever you're trying to run this code –  Mar 07 '15 at 06:01
  • Yes, from an array that has to be created I guess? – Rebecca Richardson Mar 07 '15 at 06:01
  • When I open it in my web browser & something is incorrect, the screen shows blank. When I have the code correct, it shows up as it should. Notebook ++ doesn't have a run program like eclipse does. – Rebecca Richardson Mar 07 '15 at 06:03
  • To see the browser's error console, run the JavaScript in the browser and press 'F12' button. – David Thomas Mar 07 '15 at 06:12
  • Beware, Internet Explorer is not the best browser for debugging JavaScript. Try Google Chrome or FireFox. Personally I prefer Google Chrome :) – HandyDan Mar 07 '15 at 06:14
  • @david, now that's a good work! and no need to entertain a duplicate question anymore – Vikrant Mar 07 '15 at 06:19

0 Answers0