I'm learning loops in JavaScript and
I'd like to get how to hide all text strings from output.
When alert of skipping was inside @for operator there was no NaN values in output, but it was shown 2 times undesirable alerts, that's why I moved alert block out of @for loop, and now I got another issue - shows all strings... all values (6) from array..
Here my code
<script type="text/javascript">
//Made function calc degCent
function convertToCentigrade(degFahren)
{
var degCent;
degCent = 5/9 * (degFahren - 32);
return degCent
}
// Created array with data
var degFahren = new Array(212, 32, -459.15, "Huy", 34, 50, "naxxx");
//Create var array degCent
var degCent = new Array ();
//Create Counter
var loopCounter;
//Create loop
if (isNaN(degFahren))
{
alert ("You have text parameters that will be skipped ");
}
for (loopCounter = 0; loopCounter <=6; loopCounter++)
{
// Calc degCent via function
degCent[loopCounter] = convertToCentigrade(degFahren[loopCounter]);
document.write ("Value " + loopCounter + " was " + degFahren[loopCounter] + " degrees Fahrenheit");
document.write (" which is " + degCent[loopCounter] + " degrees centigrade<br />");
}
</script>
Aucun commentaire:
Enregistrer un commentaire