我想使用5秒钟的计时器来显示消息,但出现错误。在Node.Js中。
有没有办法解决这个问题?谢谢
<!DOCTYPE html>
<html>
<body>
<h2>Javascript CART breakdown calculator</h2>
<button onclick="pause_function()">pause</button>
<button onclick="resume_speed_function()">resume</button>
<label id="seconds">0</label>
<p id="random_number_display"></p>
<p id="breakdown_item"></p>
<script>
var my_random_number, low, high;
low = 1;
high = 5;
my_random_number = Math.floor(Math.random() * high) + low;
document.getElementById("random_number_display").innerHTML = my_random_number;
var random_breakdown_event, low_event, high_event;
low_event = 1
high_event = 9
random_breakdown_event = Math.floor(Math.random() * high_event) + low_event;
var text
if (random_breakdown_event == 1) text = "blown engine";
if (random_breakdown_event == 2) text = "broken transmission";
if (random_breakdown_event == 3) text = "broken suspension";
if (random_breakdown_event == 4) text = "broken halfshaft";
if (random_breakdown_event == 5) text = "broken cv joint";
if (random_breakdown_event == 6) text = "broken wings";
if (random_breakdown_event == 7) text = "electrical misfire";
if (random_breakdown_event == 8) text = "broken fuel pump";
if (random_breakdown_event == 9) text = "change battery";
var secondsLabel = document.getElementById("seconds");
var totalSeconds = 0;
var interval_between_ticks = 1000;
//Assign the interval to a variable to keep track of it
var interval = setInterval(setTime, interval_between_ticks);
function setTime() {
++totalSeconds;
secondsLabel.innerHTML = totalSeconds;
if(my_random_number === totalSeconds){
document.getElementById("breakdown_item").innerHTML = text}
if(my_random_number === totalSeconds){
function myFunction(frequency, duration, callback) {
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var oscillator = audioCtx.createOscillator();
duration = 10000 / 1000; // the 10000 used to be 'duration'
oscillator.type = 'square';
oscillator.frequency.value = 500; // value in hertz
oscillator.connect(audioCtx.destination);
oscillator.onended = callback;
oscillator.start(0);
oscillator.stop(audioCtx.currentTime + duration);
}
}
}
function pause_function() {
interval_between_ticks = 999999999;
//Clear the old interval so we don't have memory leaks
clearInterval(interval);
//Set the interval with the new time between clicks
interval = setInterval(setTime, interval_between_ticks);
}
function resume_speed_function() {
interval_between_ticks = 1000;
//Clear the old interval so we don't have memory leaks
clearInterval(interval);
//Set the interval with the new time between clicks
interval = setInterval(setTime, interval_between_ticks);
}
</script>
</body>
</html>
答案 0 :(得分:0)
你可以试试吗
const HELP_INTENT = 'Help';
async onTurn(context) {
Switch(Intent){
case HELP_INTENT:
var reply = MessageFactory.suggestedActions(['Testing','Running'],`How do we help you?`);
await new Promise(resolve => setTimeout(() => resolve(
dc.context.sendActivity(reply)
), 5000);
break;
case NONE_INTENT:
default:
await dc.context.sendActivity(`Sorry I do not understand you.`);
break;
}