我正在制作一个javascript游戏说你所看到的,到目前为止我有这个代码
function change(name, image) {
document.images[name].src=image+".jpg";
}
<p>What is this an image of? </p>
<img src="image1.jpg" name="image1">
<form name=question1>
<input type=button value="What is your answer"
onClick="
s=prompt('Enter your answer','answer');
alert('Dog '+s+'!')">
</form>
我已经管理得到图像加载,并解释游戏,但我不知道如何使提示正常工作,所以他们输入答案,我必须告诉他们是否正确。这会是某种if声明吗?我在java脚本方面没有很多经验,感谢
答案 0 :(得分:1)
此代码应提供您要查找的内容。我确实改变了你的html,因为它有点凌乱。
查看此jsfiddle - http://jsfiddle.net/5wzmkfwx/3/
JAVASCRIPT / JQUERY
当用户点击按钮时,会触发此功能,询问图像是什么。如果给出了正确的答案,它将以正确的答案消息提醒用户。如果答案不正确,它将绕过if
语句并到达else
语句并在那里执行,通知用户正确的答案。
function checkAnswer(){
prompt('What animal is in the image?')
if('dog'){
alert('Well Done. Correct answer')
}
else{
alert('Sorry, incorrect, it is a dog')
}
}
HTML
<p>What is this an image of? </p>
<img src="http://static.ddmcdn.com/gif/earliest-dogs-660x433-130306-akita-660x433.jpg" class="image1">
<button onclick="checkAnswer()">Answer</button>
如果这是您正在寻找的,请告诉我,如果不是,我可以相应地更改。
答案 1 :(得分:0)
到目前为止,我有这个,但我不知道如何添加评分系统这将是某种变量吗?我也希望它说他们的正确答案得分为1或错误答案得分为0,最后它表示你得分为5分或4分或者其他得分!
document.write("This is a type what you see game, the objective of the game is to answer what you see on screen, by typing into the box, a correct answer will be worth 2 points, and incorrect answer will be worth 0 points, best of luck!") function checkAnswer(){ a= prompt('What animal is in the image?'); if(a=='dog'){ alert('Well Done. Correct answer'); } else{ alert('Sorry, incorrect, it is a dog'); } } function checkAnswer2(){ b= prompt('What animal is in the image?'); if(b=='hamster'){ alert('Well Done. Correct answer'); } else{ alert('Sorry, incorrect, it is a hamster'); } } function checkAnswer3(){ c= prompt('What animal is in the image?'); if(c=='hedgehog'){ alert('Well Done. Correct answer'); } else{ alert('Sorry, incorrect, it is a hedgehog'); } } function checkAnswer4(){ d= prompt('What animal is in the image?'); if(d=='turtle'){ alert('Well Done. Correct answer'); } else{ alert('Sorry, incorrect, it is a turtle'); } } function checkAnswer5(){ e= prompt('What animal is in the image?'); if(e=='turtle'){ alert('Well Done. Correct answer'); } else{ alert('Sorry, incorrect, it is a turtle'); } }
这是什么形象?
答案
这是什么形象?
答案
这是什么形象?
答案
这是什么形象?
答案
p&gt;这是什么形象?
答案