Need Help ppl
Grasshopper
Hi po.Patulong naman po dapat yung submit button is mag output ng "Output: Your Score is: (score 1-5)/5...pero young nagawa kong code is naging alert type siya
The Code:
<!DOCTYPE html>
<html>
<body>
<script>
var answers = ["A","A","B","D","C"],
tot = answers.length;
function getCheckedValue( radioName ){
var radios = document.getElementsByName( radioName ); // Get radio group by-name
for(var y=0; y<radios.length; y++)
if(radios[y].checked) return radios[y].value; // return the checked value
}
function getScore(){
var score = 0;
for (var i=0; i<tot; i++)
if(getCheckedValue("question"+i)===answers) score += 1; // increment only
return score;
}
function returnScore(){
alert("Your score is "+ getScore() +"/"+ tot);
}
</script>
<form>
<h3> 1. It is an American multinational technology company based in Menlo Park, California.</h3>
<input type="radio" name="question0" value="A"> Facebook
<input type="radio" name="question0" value="B"> Twitter
<input type="radio" name="question0" value="C"> Google
<input type="radio" name="question0" value="D"> Netflix
<h3> 2. It is an American microblogging and social networking service on which users post and interact with messages.</h3>
<input type="radio" name="question1" value="A"> Twitter
<input type="radio" name="question1" value="B"> YøùTùbé
<input type="radio" name="question1" value="C"> Google
<input type="radio" name="question1" value="D"> Microsoft
<h3> 3. It is an American multinational technology company that specializes in Internet-related services and products.</h3>
<input type="radio" name="question2" value="A"> Microsoft
<input type="radio" name="question2" value="B"> Google
<input type="radio" name="question2" value="C"> Netflix
<input type="radio" name="question2" value="D"> YøùTùbé
<h3> 4. It is an American online video sharing and social media platform owned by Google.</h3>
<input type="radio" name="question3" value="A"> Microsoft
<input type="radio" name="question3" value="B"> Tiktok
<input type="radio" name="question3" value="C"> Google Play
<input type="radio" name="question3" value="D"> YøùTùbé
<h3> 5. It is an American pay television over-the-top media service and original programming production company.</h3>
<input type="radio" name="question4" value="A"> Microsoft
<input type="radio" name="question4" value="B"> YøùTùbé
<input type="radio" name="question4" value="C"> Netflix
<input type="radio" name="question4" value="D"> Tiktok
<br> <br>
</form>
<button onclick="returnScore()">Submit</button>
</body>
</html>
The Code:
<!DOCTYPE html>
<html>
<body>
<script>
var answers = ["A","A","B","D","C"],
tot = answers.length;
function getCheckedValue( radioName ){
var radios = document.getElementsByName( radioName ); // Get radio group by-name
for(var y=0; y<radios.length; y++)
if(radios[y].checked) return radios[y].value; // return the checked value
}
function getScore(){
var score = 0;
for (var i=0; i<tot; i++)
if(getCheckedValue("question"+i)===answers) score += 1; // increment only
return score;
}
function returnScore(){
alert("Your score is "+ getScore() +"/"+ tot);
}
</script>
<form>
<h3> 1. It is an American multinational technology company based in Menlo Park, California.</h3>
<input type="radio" name="question0" value="A"> Facebook
<input type="radio" name="question0" value="B"> Twitter
<input type="radio" name="question0" value="C"> Google
<input type="radio" name="question0" value="D"> Netflix
<h3> 2. It is an American microblogging and social networking service on which users post and interact with messages.</h3>
<input type="radio" name="question1" value="A"> Twitter
<input type="radio" name="question1" value="B"> YøùTùbé
<input type="radio" name="question1" value="C"> Google
<input type="radio" name="question1" value="D"> Microsoft
<h3> 3. It is an American multinational technology company that specializes in Internet-related services and products.</h3>
<input type="radio" name="question2" value="A"> Microsoft
<input type="radio" name="question2" value="B"> Google
<input type="radio" name="question2" value="C"> Netflix
<input type="radio" name="question2" value="D"> YøùTùbé
<h3> 4. It is an American online video sharing and social media platform owned by Google.</h3>
<input type="radio" name="question3" value="A"> Microsoft
<input type="radio" name="question3" value="B"> Tiktok
<input type="radio" name="question3" value="C"> Google Play
<input type="radio" name="question3" value="D"> YøùTùbé
<h3> 5. It is an American pay television over-the-top media service and original programming production company.</h3>
<input type="radio" name="question4" value="A"> Microsoft
<input type="radio" name="question4" value="B"> YøùTùbé
<input type="radio" name="question4" value="C"> Netflix
<input type="radio" name="question4" value="D"> Tiktok
<br> <br>
</form>
<button onclick="returnScore()">Submit</button>
</body>
</html>
Last edited: