嗨,我正试图将我的movieprice数组从复选框值传递给另一个计算选择总数的函数,但我的代码没有;t运行

Hi am trying to pass my movieprices array from checkbox values to another function that calculates the total of the selections but my code doesn't run

本文关键字:我的 函数 选择 代码 计算 运行 movieprice 数组 值传 复选框 另一个      更新时间:2023-09-26

Am试图在这里定义某个函数来计算总数var总计=0;var movie_prices=[];//创建电影价格数组,但它正在等待用户选择的值,如14、16、35//函数calculateTotal(arguments){//这是被调用的函数//

 var len = arguments.length
 for(vari=0; i<len;i++){
total+= parseInt(arguments[i]); return total;
}
}
This function will display the total by determining which movies are checked;
function displayTotal(){ 
  var obj = document.getElementById('flicks'); //flicks is an id to the table element containing checkboxes//
  var top = obj.getElementByTagName('input');// reference to checkboxes of input type//
  var leng = top.length;
  for(vari=0; i< leng;i++){
    if(top[i].checked ){
     movie_prices.push(top[i].value;);
    }
  }
  call to the calculateTotal function with movieprices array as an argument;
    calculateTotal(movie_prices);
    window.alert("The total amount you now owe is:" + total); // display total//
}

到目前为止,我看到了两件事。第七行应该是一个注释,所以如果你在运行时没有注释掉它,那就会给你带来错误。

此外,方法top[i].value似乎未定义。您在代码中的何处声明了值?