不确定为什么我的JavaScript代码不起作用?

时间:2017-10-06 04:15:56

标签: javascript

在我==语句中与0比较时,我一直收到错误消息,说我无法使用if。我的代码中有什么错误,因为我已经查看了它,而且我不确定为什么我的代码没有运行

var table=[];                            // declare table array. 
var fiveTable=[], tenTable=[],squareTable=[];   //declare fiveTable, tenTable, and squareTable array


for(var i =1;i<=10;i++)     //This for loop will populate the table array. 
{
table[i]=i;
}   

for(var i=0; i<101;i++) //This for loop will populate the fiveTable, tenTable, and squareTable array
{


if(i+1<=51)  //Stops populating fiveTable once i reachs 51
{

    fiveTable[i]=5*(i+1);

}

if(i+1<=101)
//Stops populating fiveTable once i reachs 101      
{

    tenTable[i]=10*(i+1);

}

if(i+1<=10)
//Stops populating squareTable once i reachs 10     
{

    squareTable[i]=table[i]*table[i];

}


}

console.log("These are the odd multiples of 5 between 1 and 100"); //Prints a string

for(var i=1;i<=100;i++) 
{
    if(i%2!=0&&i%5==0) //Checks if i is odd and a multiple of 5
{
    console.log(i); //prints all odd multiples of 5
}           
}

console.log("These are the sum of even multiples of 7 between 1 and 100");

for(var i=1;i<=100;i++)
{
if(i%2==0&&i%7==0)  //Checks if i is even and a multiple of 7
{
    console.log(i); //prints all even multiples of 7
}
}
console.log("          **************Problem #5 Curry 
Function***************");
function cylinder_volume(r){ //This is the start of the curried function
return function(h){// returning a function 
return 3.14*r*r*h; // This will the return the value that is desired from 
the function
};
}

var r=5; // initialize r with 5
var h=10;// initialize h with 10
console.log(cylinder_volume(r)(h));//  prints the value of the curried 


console.log("          **************EXTRA**********CREDIT***************");

console.log("These are the even multiples of 5 between 1 and 100"); //Prints a string

for(var i=1;i<=100;i++) 
{
    if(i%2==0&&i%5==0) //Checks if i is even and a multiple of 5
{
    console.log(i); //prints all even multiples of 5
}           
}

console.log("These are the sum of odd multiples of 7 between 1 and 100");

for(var i=1;i<=100;i++)
{
if(i%2!=0&&i%7==0)  //Checks if i is odd and a multiple of 7
{
    console.log(i); //prints all odd multiples of 7
}
}

0 个答案:

没有答案