LeMoustache LeMoustache - 4 months ago 8
Javascript Question

Program returns undefined

I try to fill out a form but it only returns undefined. There will be more codes in the array.



var codes = ["OHLV-NF12-KTV7-VELO-QPX5"]
var i = 0;
while(i>codes.length){
document.getElementsByClassName('redeem-input-text-box id-track-click')[0].value=codes[i];
i++
}




Answer

var i=0 and codes.length=1 when use while(i>codes.length){ never run code Because 0 is not greater than 1 .

So ,

Change :

 while(i>codes.length){

To :

 while(i<codes.length){

Example :

<html>
<head>
</head>
    <body>
	   <p class="redeem"></p>
        <script>
            var codes = ["OHLV-NF12-KTV7-VELO-QPX5"];
            var i = 0;
            while(i<codes.length){
            document.getElementsByClassName("redeem")[0].innerHTML=codes[i];
            i++
            }
        </script>
    </body>     
</html> 

Comments