使用Javascript函数错误更新变量

使用Javascript函数错误更新变量,javascript,jquery,Javascript,Jquery,使用javascript函数更新变量q的值时遇到问题。我有一个计时器,当按下“播放”键时开始计时,然后持续启动当前的请求功能 $(document).ready(function(){ $("#main_video").on( "timeupdate", function(event){ currentDemand(this.currentTime); }); }); // Initiate Demand var q = 0; function

使用javascript函数更新变量
q
的值时遇到问题。我有一个计时器,当按下“播放”键时开始计时,然后持续启动当前的请求功能

$(document).ready(function(){

  $("#main_video").on(
    "timeupdate", 
    function(event){
      currentDemand(this.currentTime);
    });
}); 

// Initiate Demand
var q = 0;

function currentDemand(currentTime){

    console.log(currentTime);

    if ( 0 <= currentTime < 10) {
        q === 0;
    }
    else if ( 10 <= currentTime < 12.5 || 57.5 <= 60) {
        q === 1;
    }
    else if ( 12.5 <= currentTime < 17.5 || 55 <= currentTime < 57.5) {
        q === 2;
    }
    else if ( 17.5 <= currentTime < 20 || 50 <= currentTime < 55) {
        q === 3;
    }
    else if (20 <= currentTime < 25 || 47.5 <= currentTime < 50) {
        q === 4;
    }
    else if ( 25 <= currentTime < 27.5 || 45 <= currentTime < 47.5 ) {
        q === 5;
    }
    else if ( 27.5 <= currentTime < 32.5 || 42500 <= currentTime < 45 ) {
        q === 6;
    }
    else if ( 32.5 <= currentTime < 35 || 40 <= currentTime < 42.5 ) {
        q === 7;
    }
    else if ( 45 <= currentTime < 47.5 ) {
        q === 8;
    }

    console.log(q);
    $("#currentDemand").text(q);
}
$(文档).ready(函数(){
$(“#主视频”)。在(
“时间更新”,
功能(事件){
currentDemand(此.currentTime);
});
}); 
//提出要求
var q=0;
函数currentDemand(currentTime){
console.log(当前时间);

如果(0
q=whatevernumber;


q===whatevernumber
,它返回一个布尔值
q=whatevernumber;


不是
q===whatevernumber
,它返回一个布尔值来赋值,如果使用
=
==
进行比较,则只能使用一个
=
。此处的详细信息:


要分配值,如果使用的是比较性的
=
==
则只能使用一个
=
。更多信息请参见:


您应该使用一个相等的
=
用于目的,双
=
和三
==
相等用于

此外,您还应将您的情况分开,使其看起来像:

if ( currentTime >= 0 && currentTime < 10) {
    q = 0;
}
else if ( currentTime >= 10 && currentTime < 12.5 || 57.5 <= 60) {
//__________________________________________________^__________^ 
//this condition should be removed because it return always true
    q = 1;
}
else
.....
if(currentTime>=0&¤tTime<10){
q=0;
}

否则,如果(currentTime>=10&¤tTime<12.5 | 57.5您应该使用一个相等的
=
用于目的,则双
==
和三
==
等用于

此外,您还应将您的情况分开,使其看起来像:

if ( currentTime >= 0 && currentTime < 10) {
    q = 0;
}
else if ( currentTime >= 10 && currentTime < 12.5 || 57.5 <= 60) {
//__________________________________________________^__________^ 
//this condition should be removed because it return always true
    q = 1;
}
else
.....
if(currentTime>=0&¤tTime<10){
q=0;
}

否则,如果(currentTime>=10&¤tTime<12.5 | | 57.5这不是测试
currentTime
是否在两个值之间的正确方法:

else if ( 10 <= currentTime < 12.5 || 57.5 <= 60) {

如果
currentTime
介于两个值之间,则这不是正确的测试方法:

else if ( 10 <= currentTime < 12.5 || 57.5 <= 60) {

您不是在应用/分配值,而是在比较(
strict
)您不是在应用/分配值,而是在比较(
strict
)这并没有解决问题,随着时间的推移,q仍然记录为零。还有其他想法吗?你也应该解决条件..检查我的更新。这并没有解决问题,随着时间的推移,q仍然记录为零。还有其他想法吗?你也应该解决条件..检查我的更新。这并没有解决问题,随着时间的推移,q仍然记录为零。有什么想法吗其他想法?你确定如果在if语句中更改“==”,它仍然返回零吗?尝试在if中插入一个console.log(),如果要检查没有解决问题的enter的位置,随着时间的推移,q仍然记录为零。还有其他想法吗?你确定如果在if语句中更改“==”,它仍然返回零吗?尝试插入一个console.log()如果要在内部检查未解决问题的条目的位置,随着时间的推移,q仍然记录为零。有其他想法吗?分解此:0没有解决问题,q仍然记录为零。有其他想法吗?分解此:0