简体   繁体   English

在进行计算时,如何获得某个值以对应另一个值? 以前有过,现在不知道哪里出错了

[英]How can I get a certain value to correspond to another when doing a calculation? I had it previously, now I can't figure out where I went wrong

var resetButton = document.getElementById("reset");
var girlMeasuring = document.getElementById("girl");
var guyWithCaliper = document.getElementById("caliperGuy");
var resultButton = document.getElementById("button");
var drakeGif = document.getElementById("drake");
var whatHappened = document.getElementById("spiderman");
var dissaPointing = document.getElementById("disappointGuy");
const pressResetMsg = document.getElementById("pressResetMsg");
var calcResult = document.getElementById("result");
var thkInput = document.getElementById("thickness");
var thkLabel = document.getElementById("thkLabel")



thkInput.addEventListener("input", function(){
  if (document.getElementById("thickness").value > 1) {
    thkLabel.innerHTML = "Gauge: ";
  } else {
    thkLabel.innerHTML = "Thickness: ";
  }
});



resultButton.addEventListener("click", function() {




  if (thkInput.value > 1) {
    let thkIn = [7, 10, 11, 12, 13, 14, 16, 18, 19, 20, 22, 24, 26, 28];
    let thkOut = [.1793, .1345, .1196, .1046, .0897, .0747, .0598, .0478, .0418, .0359, .0299, .0239, .0179, .0149];
    let inPosition = thkIn.indexOf(thkInput);
    thkInput = (thkOut[inPosition]);
      }

  var sumBends = Number(document.getElementById("bend1").value) +
    Number(document.getElementById("bend2").value) +
    Number(document.getElementById("bend3").value) +
    Number(document.getElementById("bend4").value) +
    Number(document.getElementById("bend5").value) +
    Number(document.getElementById("bend6").value) +
    Number(document.getElementById("bend7").value) +
    Number(document.getElementById("bend8").value);
  var totalBends = Number(document.getElementById("totalbends").value);

  var bendDeduction = (Number(thkInput.value) * 1.55) * totalBends;
  var totalResult = (sumBends - bendDeduction).toFixed(3);
  calcResult.innerHTML = totalResult;

  if (totalResult === "0.000") {
    whatHappened.style.display = "inline-block";
    guyWithCaliper.style.display = "none";
    dissaPointing.style.display = "inline-block";
    pressResetMsg.style.display = "inline-block";
    resultButton.innerHTML = "<s>RESULT</s>";
    resultButton.style.opacity = ".1";
    calcResult.innerHTML = "";

  } else {
    girlMeasuring.style.display = "inline-block";
    guyWithCaliper.style.display = "none";

  }

});

This is my code.这是我的代码。 You can probably tell I am brand new to all of this.你可能会说我对这一切都是全新的。 I had a problem where the bendDeduction kept coming up as 0, and when I fixed it, I ran into another problem.我遇到了一个问题,bendDeduction 一直显示为 0,当我修复它时,我遇到了另一个问题。

Currently, you can enter in a decimal thickness, and that number is used in the calculation.目前,您可以输入小数厚度,该数字用于计算。 When it is entered as a thickness it runs correctly and I get the right result.当它作为厚度输入时,它运行正确,我得到了正确的结果。

Previously, I was able to also just write a corresponding whole gauge number (7, 10, 11, 12 etc. in the array) and that number would correspond to the correct decimal thickness internally and process the same result.以前,我也可以只写一个相应的完整规格数(数组中的 7、10、11、12 等),该数字将对应于内部正确的十进制厚度并处理相同的结果。 However, that I have fixed the subtraction issue, if I enter a number above 1, I can't even press enter.但是,我已经解决了减法问题,如果我输入一个大于 1 的数字,我什至不能按 Enter。

Error message for:错误消息:

  var bendDeduction = (Number(thkInput.value) * 1.55) * totalBends;

is

calculation.js:47 Uncaught TypeError: Cannot read property 'value' of undefined
    at HTMLButtonElement.<anonymous> (calculation.js:47)

Why is thkInput.value undefined now?为什么 thkInput.value 现在未定义?

Thank you for any help感谢您的任何帮助


  if (Number(thkInput.value) > 1) {
    let thkIn = [7, 10, 11, 12, 13, 14, 16, 18, 19, 20, 22, 24, 26, 28];
console.log(thkIn);
    let thkOut = [.1793, .1345, .1196, .1046, .0897, .0747, .0598, .0478, .0418, .0359, .0299, .0239, .0179, .0149];
console.log(thkOut);    
    let inPosition = thkIn.indexOf(Number(thkInput.value));
console.log(inPosition);
     thkInput.value = (thkOut[inPosition]);
console.log(thkInput.value);
      }

This got me my solution.这给了我我的解决方案。 Sorry to take anyone else's time对不起占用别人的时间

暂无
暂无

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

相关问题 CSS-有人可以帮助我找出下拉菜单导航出现的问题吗? - CSS - Can someone help me figure out where I went wrong with my dropdown menu nav? 我不知道如何在另一个函数中调用先前创建的函数? - I can't figure out How to call previously created function inside another function? 我不知道我在使用 getDay() 时做错了什么 - I can't figure out what I'm doing wrong with getDay() 循环执行不正确,无法弄清楚我在做什么 - Loop implemented incorrectly, can't figure out what I'm doing wrong 我不知道这个正则表达式做错了什么,它应该匹配 id&quot;:&quot; 和 &quot; - I can't figure out what i'm doing wrong with this regex, it's suposed to match everything between id":" and " Javascript:使用for循环和子字符串的递归函数示例-无法弄清楚我要去哪里 - Javascript: Example of recursive function using for loops and substring - can't figure out where I'm going wrong 我不知道怎么了 - I can't figure out what's wrong 播放阵列中随机选择的音频,无法弄清楚我哪里出了错 - playing a randomly selected piece of audio from an array, cant figure out where I went wrong 有人可以告诉我哪里出错了吗? - Can someone please tell me where I went wrong? 我似乎无法弄清楚为什么第三个函数在其他两个函数之前运行,即使我使用的是 Promises。 我究竟做错了什么? - I can't seem to figure out why the third function runs before the other two even though I am using Promises. What am I doing wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM