// Test
// Analysis

for(x=0; x<=255; x++)
	{
	document.writeln("toHex(" + x + "): " + toHex(x) + "<br>");
	if(x%16 == 15)
		document.writeln("<p>");
	}

Conclusive testing for this function is easy: this code simply sets up a for loop that loops through the values 0 to 255, calling the toHex function for each value. Once again, the test value is printed to the screen as well as the result to ensure that the function is working correctly.

Although it was not necessary to the testing procedure, I added some extra code to put a new paragraph marker in after every 16th loop. This will help format the output into blocks of 16, and make it easier to understand hexadecimal numbering.

Close Window