function start() { var theArray = [0,0,0,0,0,0,0,0,0,0]; var isduplicate = false
ID: 674085 • Letter: F
Question
function start()
{
var theArray = [0,0,0,0,0,0,0,0,0,0];
var isduplicate = false ;
var input;
var strList;
for ( var i = 0; i < theArray.length; ++i )
{
input = parseInt(prompt("Enter Number between 10 to 100"));
theArray[i] = input;
//prompt user for a number
// convert to intger
// compare the result 10 to 100
if (input > 100 || input < 10 )
{
window.alert ( "invalid");
}
else
{
isduplicate = false;
// compare dubicate
for (var k=0; k<theArray.length; k++)
{
if (input == theArray[k] && k != i)
{
//this is a duplicate
isduplicate = true;
break;
}
}
if (!isduplicate)
{
// if not duplicate then insert to the array at I and add to string list
//
strList = strList + " " + input;
}
}
}
document.writeln(strList);
//results += "<p>Total using for...in: " + total2 + "</p>";
//document.getElementById( "output" ).innerHTML = results;
} // end function start
window.addEventListener( "load", start, false );
this is my code
when i run it
it shows undefined
i wanna get it out
what i am missing ??
Explanation / Answer
function start()
{
var theArray = [0,0,0,0,0,0,0,0,0,0];
var isduplicate = false ;
var input;
var strList="";
for ( var i = 0; i < theArray.length; ++i )
{
input = parseInt(prompt("Enter Number between 10 to 100"));
theArray[i] = input;
//prompt user for a number
// convert to intger
// compare the result 10 to 100
if (input > 100 || input < 10 )
{
window.alert ( "invalid");
}
else
{
isduplicate = false;
// compare dubicate
for (var k=0; k<theArray.length; k++)
{
if (input == theArray[k] && k != i)
{
//this is a duplicate
isduplicate = true;
break;
}
}
if (!isduplicate)
{
// if not duplicate then insert to the array at I and add to string list
//
strList = strList + " " + input;
}
}
}
document.writeln(strList);
//results += "<p>Total using for...in: " + total2 + "</p>";
//document.getElementById( "output" ).innerHTML = results;
} // end function start
window.addEventListener( "load", start, false );
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.