一切正常運行,但我想添加一些東西。在函數的最後,我想通過比較你想要回答的數量,但是用一個百分比來改變畫布的高度。很抱歉,如果這很難理解。使用if語句來獲得輸入的百分比?
的JavaScript:
<script type="text/javascript">
function myFunction() {
score = 0;
questionAmount = prompt('How many question would you like to solve?');
for(i = 0; i < questionAmount; i++) {
var x = Math.floor(Math.random() * 13);
var y = Math.floor(Math.random() * 13);
question = prompt('What is ' + x + ' * ' + y + ' = ?');
if(question == null || isNaN(question)) {
break;
}
if(question == x * y) {
score++;
}
}
alert('You got ' + score + ' out of ' + questionAmount + ' correct.');
}
</script>
HTML:
<canvas id="content"></canvas>
<br />
<button onclick="myFunction()">CLICK</button>
所以,你想一些酒吧,是更大的,當用戶有更多的問題正確? [類似這樣的東西?](http://www.asp.net/ajaxlibrary/GetFile.aspx?Page=jquery_ui_mvc_progressbar&File=basic.PNG) – Kevin
你遇到了什麼問題? – Bergi
是的,凱文,這個例子與我想要的非常相似。 – user2793503