added a version of javascript to implement quiz

git-svn-id: svn+ssh://atelier.inf.usi.ch/home/bevilj/group-1@161 a672b425-5310-4d7a-af5c-997e18724b81
This commit is contained in:
annoum 2018-11-13 15:02:30 +00:00
parent 786008641f
commit 08ee4cd03f
2 changed files with 114 additions and 0 deletions

View File

@ -30,3 +30,66 @@ Yeah, right, there is a quiz.
<!-- quiz di javascript pronto che linkero -->
<link href ="style.css" rel ="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<script src = "main.js"></script>
</head>
<body>
<h1>Are you ready for the quiz?</h1>
<form id = "quiz" name = "quiz">
<!--1-->
<p class = "questions">What is path?</p>
<input type = "radio" id = "mc" name = "question1" value = "Is a location to a folder or file in a file system of a Operating System"> Is a location to a folder or file in a file system of a Operating System<br>
<input type = "radio" id = "mc" name = "question1" value = "Is an Operating System"> Is an Operating System<br>
<input type = "radio" id = "mc" name = "question1" value = "Is a folder that you can find on your Operating System"> Is a folder that you can find on your Operating System<br>
<!--2-->
<p class = "questions">What is an absolute path?</p>
<input type = "radio" id = "mc" name = "question2" value = "The bigger folder that you can find on your Operating System"> The bigger folder that you can find on your Operating System<br>
<input type = "radio" id = "mc" name = "question2" value = "Is defined as specifying the location of a file or directory from the root directory(/)"> Is defined as specifying the location of a file or directory from the root directory(/)<br>
<input type = "radio" id = "mc" name = "question2" value = "The last location of a file or directory from Documents"> The last location of a file or directory from Documents<br>
<p class = "questions">"cat /home/a1/group1.txt" it's an example of absolute path?</p>
<input type = "radio" id = "mc" name = "question3" value = "YES"> YES <br>
<input type = "radio" id = "mc" name = "question3" value = "NO"> NO <br>
<p class = "questions">If you choose "NO" why it's not correct? if you think it's correct don't write anything</p>
<input id = "textbox" type = "text" name = "question4">
<p class = "questions">"pwd/home/user1cd Documents" it's an example of relative path?</p>
<input type = "radio" id = "mc" name = "question5" value = "YES"> YES <br>
<input type = "radio" id = "mc" name = "question5" value = "NO"> NO <br>
<br><br><input id = "button" type = "button" value = "Finish? Sure!?" onclick = "check();">
</form>
<div id = "after_submit">
<p id = "number_correct"></p>
<p id = "message"></p>
<img id = "picture">
</div>

View File

@ -0,0 +1,51 @@
function check(){
var question1 = document.quiz.question1.value;
var question2 = document.quiz.question2.value;
var question3 = document.quiz.question3.value;
var question4 = document.quiz.question4.value;
var question5 = document.quiz.question5.value;
var correct = 0;
if (question1 == "Is a location to a folder or file in a file system of a Operating System") {
correct++;
}
if (question2 == "Is defined as specifying the location of a file or directory from the root directory(/)") {
correct++;
}
if (question3 == "YES") {
correct++;
}
if (question4 == "") {
correct++;
}
var pictures = ["img/win.gif", "img/meh.jpeg", "img/lose.gif"];
var messages = ["Great job!", "That's just okay", "You really need to do better"];
var score;
if (correct == 0) {
score = 3;
}
if (correct > 0 && correct < 4) {
score = 2;
}
if (correct == 4) {
score = 0;
}
document.getElementById("after_submit").style.visibility = "visible";
document.getElementById("message").innerHTML = messages[score];
document.getElementById("number_correct").innerHTML = "You got " + correct + " correct.";
document.getElementById("picture").src = pictures[score];
}
v0dfsew