简体   繁体   English

js中的衣服尺寸计算器

[英]Clothes size calculator in js

I am now doing a clothes size calculator widget in js, now it checks for the values in the inputs using this我现在正在 js 中做一个衣服尺寸计算器小部件,现在它使用这个检查输入中的值

var sizes= [];
//Array containing example sizes
sizes[0] = ["XS", "1", "2", "4"];
sizes[1] = ["S", "6", "7", "9"];
sizes[2] = ["M", "11", "13", "15"];
sizes[3] = ["L", "17", "19", "22"];
sizes[4] = ["XL", "24", "27", "28"];
sizes[5] = ["XXL", "30", "32", "34"];
//In this function I receive values for the length, width and sleeve length from an HTML form and compare whether they are smaller than the clothes size
function rightSize(lon, alt, sleeve){
  console.clear();

  for (i=0; i < sizes.length; i++) {
    var rightLon = lon < sizes[i][1];
    var rightAlt = alt < sizes[i][1];
    var rightSleeve = sleeve < sizes[i][1];

    console.log("iteration: " + i +  rightLon);
    console.log("iteration: " + i +  rightAlt);
    console.log("iteration: " + i +  rightSleeve);
    if(rightLon  && rightAlt && rightSleeve ){
        alert("Size: " + sizes[i][0]);
       break;
    }
  }
}

But when I call it with almost every value it returns S as the correct value.但是当我用几乎每个值调用它时,它都会返回 S 作为正确值。

EDIT: Here's the HTML form-编辑:这是 HTML 表单-

<input type="number" name="largo" id="lon">
<input type="number" name="alto" id="alt">
<input type="number" name="ancho" id="sleeve">
<INPUT TYPE="button" NAME="button" Value="Click"onClick="rightSize(document.getElementById('lon').value, document.getElementById('alt').value, document.getElementById('sleeve').value)">

I think you just made a typo in the rightSize() function.我认为您只是在rightSize()函数中rightSize()rightSize() Your old code had rightLon, rightAlt, and rightSleeve all using sizes[i][1]您的旧代码具有 rightLon、rightAlt 和 rightSleeve,均使用 size sizes[i][1]

EDIT: Also, you had for(i=0;i<talles.length;i++) instead of for(var i =0;编辑:另外,你有for(i=0;i<talles.length;i++)而不是for(var i =0;

var sizes= [];
//Array containing example sizes
sizes[0] = ["XS", "1", "2", "4"];
sizes[1] = ["S", "6", "7", "9"];
sizes[2] = ["M", "11", "13", "15"];
sizes[3] = ["L", "17", "19", "22"];
sizes[4] = ["XL", "24", "27", "28"];
sizes[5] = ["XXL", "30", "32", "34"];
//In this function I receive values for the length, width and sleeve length from an HTML form and compare whether they are smaller than the     clothes size
function rightSize(lon, alt, sleeve){
  console.clear();

  for (var i=0; i < talles.length; i++) {
    var rightLon = lon < sizes[i][1];
    var rightAlt = alt < sizes[i][2];
    var rightSleeve = sleeve < sizes[i][3];

    console.log("iteration: " + i +  rightLon);
    console.log("iteration: " + i +  rightAlt);
    console.log("iteration: " + i +  rightSleeve);
  }
}

Please tell me in the comments if this still doesn't work.如果这仍然不起作用,请在评论中告诉我。

Spent a day and a half trying to figure it out.花了一天半的时间试图弄清楚。 It was the "".原来是“”。 I was comparing numbers to strings.我正在将数字与字符串进行比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM