1

After look at it over with my group, we are still having trouble figuring out why it won't output the number that we type into the "textInput".

var gpa = "minimumGPA";
textInput("minimumGPA", "Enter Minimum GPA");
setPosition("minimumGPA", 55, 145, 200, 30);
setText("minimumGPA", "");
onEvent("startButton", "click", function() {
  gpa = getNumber("minimumGPA");
});
console.log(gpa);

In this pseudo code, the "startButton" is an ID that works, and "getNumber" is supposed to get the number out of the textbox from the "textInput".

Anyone with experience in code.org, what's wrong with the logic of my code?

4

2 回答 2

1

“startButton”需要定义为一个按钮,您将点击该按钮。

按钮(“开始按钮”,“开始”);

此外,当您单击按钮时,您似乎正在寻找的是“minimumGPA”文本字段中的值。因此,console.log(gpa) 需要在点击处理程序中,就像这样

onEvent("startButton", "click", function() {
  gpa = getNumber("minimumGPA");
  console.log(gpa);
});

这是完整的示例(当您单击它时,对文本进行了细微的更改)

var gpa = "minimumGPA";
button("startButton","Start");
textInput("minimumGPA", "Enter Minimum GPA");
setPosition("minimumGPA", 55, 145, 200, 30);
onEvent("minimumGPA","click",function() {
  setText("minimumGPA","")
})
onEvent("startButton", "click", function() {
  gpa = getNumber("minimumGPA");
  console.log(gpa);
});
于 2019-03-19T22:43:19.420 回答
0

console.log语句不在点击处理函数中;它立即执行,而不是startButton单击时执行。在{ }您设置gpa.

于 2019-03-19T22:36:01.870 回答