【发布时间】:2018-08-12 16:03:55
【问题描述】:
好吧,这就是我卡住的地方。对于我在这个基本程序中的最后一个条件。如果用户收到 0 分,我想添加图像。如何添加图像。我已经在 .js 和 .html 文件所在的文件夹中放了一张图片。但是插入我存档的图像的代码是什么。我在.js中写了注释,所以你们也许可以理解。
//user score is 0
var userscore = 0;
//this is question 1
var question1 = prompt('What is 2 + 2?');
if (question1 === "4")
{ userscore = userscore +1;
alert("Congrats thats right!");}
else { alert("that is incorrect try again")}
//this is question 2
var question2 = prompt('What is 2 * 2?');
if(question2==="4")
{ userscore = userscore +1;
alert("Congrats thats right!")}
else {alert("that is incorrect try again")}
//this is question 3
var question3 = prompt("what is 20 + 5?");
if(question3 === "25")
{userscore = userscore +1;
alert("Congrats thats right!")}
else{alert("that is incorrect try again")}
//Scoring Guide
if (userscore === 2)
{document.write("Congrats You have passed the test with a score of 2/3")}
if(userscore === 3)
{document.write("Congrats You have passed the test with a score of 3/3")}
if(userscore === 1)
{document.write("You Failed with a score of 1/3, you are not very Bright")}
if(userscore === 0)
{document.write("You have a score of 0, your a complete idiot.")}
//I want to add an image instead of the document.write command for the last line if they recieve a score o 0
【问题讨论】:
-
我是将 img 添加到 html 文件还是 .js 文件中???
-
@fahimsterrrrr 检查我的解决方案,如果您有任何问题,请告诉我。如果有效,请将其标记为正确,以便可能有类似问题的其他人看到答案。
标签: javascript html image conditional