警报仅显示部分参数

时间:2015-02-08 09:52:31

标签: javascript

这是我工作的片段/ HTML。



<script language="javascript">

var imagesArray = [
'images/img-1.jpg',
'images/img-2.jpg',
'images/img-3.jpg',
'images/img-4.jpg',
'images/img-5.jpg',
'images/img-6.jpg',
'images/img-7.jpg'
];

var usedImages = {};
var usedImagesCount = 0;
var score = 0;

function displayImage(){

    var num = Math.floor(Math.random() * (imagesArray.length));
    if (!usedImages[num]){
        document.canvas.src = imagesArray[num];
        usedImages[num] = true;
        usedImagesCount++;
        if (usedImagesCount === imagesArray.length){
            usedImagesCount = 0;
            usedImages = {};
        }
    } else {
        displayImage();
    }
}

function check(){
	x = prompt('What is the movie title?');
	var y;
	if (document.canvas.src=='images/img-1.jpg'){
		y = 'The Expandables';}
	if (document.canvas.src=='images/img-2.jpg'){
		y = 'License to Wed';}
	if (document.canvas.src=='images/img-3.jpg'){
		y = "Schindler's List";}
	if (document.canvas.src=='images/img-4.jpg'){
		y = 'The Heartbreak Kid';}
	if (document.canvas.src=='images/img-5.jpg'){
		y = 'The Interview';}
	if (document.canvas.src=='images/img-6.jpg'){
		y = 'How To Train Your Dragon 2';}
	if (document.canvas.src=='images/img-7.jpg'){
		y = 'Avatar';}
	if (y == x){
		score = score + 10;
		alert('Your points is ', score ,'.');}
	else{
		score = score;
		alert('Your points is ', score ,'.')}
		
	
	var num = Math.floor(Math.random() * (imagesArray.length));
    if (!usedImages[num]){
        document.canvas.src = imagesArray[num];
        usedImages[num] = true;
        usedImagesCount++;
        if (usedImagesCount === imagesArray.length){
            usedImagesCount = 0;
            usedImages = {};
        }
    } else {
        displayImage();
    }
	
}
</script>
&#13;
<html>
<body>
<form name="imageForm">
  <table border=3>
   <tr align="center">
    <td>
      <input onclick="displayImage();" type=button value="Start!">
    </td>
  </tr>
  <tr>
    <td>
      <img src="blank.jpg" name="canvas" />
    </td>
  </tr>
  </table>
	<input onclick="check();" type=button value="Answer!">
</form>
 </body>
</html>
&#13;
&#13;
&#13;

当我运行JScr​​ipt时: 输出正常,但JScript警报为:

  

你的观点是

无论我的回答是对还是错。

为什么不显示分数?我的错是什么?

1 个答案:

答案 0 :(得分:1)

您可以使用+连接字符串,而不是使用,

alert('Your score is ' + score + '.');