什么这行代码的意思

问题描述:

function nxt() { 
    if(lights < imgLen-1) { 
     lights++; 
    } else { 
     lights=0;     
    } 

    imgElement.src = img[lights];      
} 

我研究这个代码,但我仍然不知道这意味着什么,所以有人可以帮我解释什么的每行代码并/指 三江源 能有人请解释一下这是什么意思什么这行代码的意思

+7

[**开始学习JavaScript **](https://developer.mozilla.org/en-US/docs/Learn/JavaScript) – adeneo

+1

堆栈溢出是实际的,具体的问题。这个问题不可能对未来的访问者有用。你还没有解释代码会让你感到困惑,它来自哪里,你正在尝试使用它等等。如果这是一个家庭作业问题:*询问作业帮助的问题必须包括你工作的摘要到目前为止,我们已经完成了解决这个问题的工作,并描述了解决这个问题的难点。 – BSMP

+1

噢,天啊,这又是糟糕的JavaScript交通灯。这些问题来自哪些学校?他们已经持续了好几个月了! – Boann

function nxt() -- function named nxt 
{ 
    if(lights < imgLen-1) -- if variable named lights is less than the length of imgLen - 1 
     { 
      lights++; -- increment the lights variable 
     } 
    else{ 
      lights=0; -- make lights equal 0    
     } 

     imgElement.src = img[lights]; -- the imgElement source will be set to whatever is stored in the array at index of lights, which will be numerical     
} 

当我看到你的问题时,好像你是初学者。我不知道你对编程有什么了解,但你应该尝试研究基础知识。

另一方面,你可以说你已经理解了。 :P

function nxt() // Create a new function. nxt probably mean "next" 
{ // Delimite the start of the function 
    if(lights < imgLen-1) // If the value of lights is under the value of imgLen - 1 
     { 
      lights++; // Then we add 1 to the value of lights 
     } 
    else{ // OTHERWISE 
      lights=0; // We set the value of Lights to 0    
     } 
     imgElement.src = img[lights]; // Finally, we assign the imgElement with the img adress by the img at the pos of the value of lights      
}