Visual Studio Code不会让我调试我编写的特定代码

时间:2019-03-20 18:28:30

标签: javascript

我在上大学时遇到问题。我正在尝试调试程序,但是Visual Studio Code不允许我这样做,而是说:“正在等待调试器断开连接...”,问题仅在于特定的代码。 请帮助我解决问题,因为我整天都在尝试在代码中查找问题,并最终决定在此处提出问题。 预先感谢!

echo 'gtag(\'event\', \'conversion\', {\'send_to\': \'AW-12345678901234567890123456\'});'

2 个答案:

答案 0 :(得分:0)

问题在于,由于最后一行未调用函数,因此未调用该函数。添加括号,以便将数组作为参数传递:

summerOutfit([16,'Morning'])

当我使用括号时,我得到以下输出:

It's 16 degrees, get your Sweatshirt and Sneakers.

没有括号,您要求的是SummerOutfit数组的值,该值为16,“早晨”不存在。

答案 1 :(得分:0)

函数调用使用()而不是[],您可能会感到困惑,因为您的函数参数是一个数组

function summerOutfit(input) {
  let degrees = Number(input.shift());
  let dayType = input.shift();

  var outfit;
  var shoes;

  if (degrees >= 10 && degrees <= 18) {
    if (dayType == 'Morning') {
      outfit = 'Sweatshirt';
      shoes = 'Sneakers';
    } else if (dayType == 'Afternoon') {
      outfit = 'Shirt';
      shoes = 'Moccasins';
    } else if (dayType == 'Evening') {
      outfit = 'Shirt';
      shoes = 'Moccasins';
    }
  } else if (degrees > 18 && degrees <= 24) {
    if (dayType == 'Morning') {
      outfit = 'Shirt';
      shoes = 'Moccasins';
    } else if (dayType == 'Afternoon') {
      outfit = 'T-Shirt';
      shoes = 'Sandals';
    } else if (dayType == 'Evening') {
      outfit = 'Shirt';
      shoes = 'Moccasins';
    }
  } else if (degrees >= 25) {
    if (dayType == 'Morning') {
      outfit = 'T-shirt';
      shoes = 'Sandals';
    } else if (dayType == 'Afternoon') {
      outfit = 'Swim Suit';
      shoes = 'Barefoot';
    } else if (dayType == 'Evening') {
      outfit = 'Shirt';
      shoes = 'Moccasins';
    }
  }

  console.log(`It's ${degrees} degrees, get your ${outfit} and ${shoes}.`);
}

summerOutfit([16, 'Morning']);