Skip to main content
Known Participant
September 6, 2024
Question

why the score doesn't appear or even increase , Adobe Animate, HTML5, Javascript

  • September 6, 2024
  • 1 reply
  • 241 views

I create an quiz using html5 canvas in Adobe Animate 
 if  click on the correct answer, it will increase the score to 10

but in my project it's not working i'm a new in adobe animate

here variabel I'm use : 

 

var data = [{
	pertanyaan_text: "Berapakah Jenis Bekam",
	jawaban_benar: "1",
	pilihan_jawaban: ["1", "2", "3","4"]
}, {
	pertanyaan_text: "Bekam yang dilakukan dengan memberikan perlukaan disebut",
	jawaban_benar: "1",
	pilihan_jawaban: ["Bekam Kering", "Bekam Basah", "Bekam Luncur","Bekam Pijat"]
}, {
	pertanyaan_text: "Salah satu Kontraindikasi Absolut Bekam adalah",
	jawaban_benar: "0",
	pilihan_jawaban: ["Hemofilia", "Hipertensi", "Anak-anak","Sakit Kepala"]
}, ];

var indexPertanyaan = 0;
var currentPertanyaan;
var score = 0;
var IsAnswer=false;

 

and here the function to load the question and answer , they are willbe randomizing

 

function loadPertanyaan(e){
//randomizing question
data= mixed(data);
	
//First Question
currentPertanyaan = data[indexPertanyaan];
	
//load the question
this.mc_kuis.txt_Pertanyaan.text = currentPertanyaan.pertanyaan_text;
	
//Randomizing the answer dan load to button
var acakJawaban = mixed(currentPertanyaan.pilihan_jawaban);
this.mc_kuis.bt_jawaban1.txt_Jawaban.text = acakJawaban[0];
this.mc_kuis.bt_jawaban2.txt_Jawaban.text = acakJawaban[1];
this.mc_kuis.bt_jawaban3.txt_Jawaban.text = acakJawaban[2];
this.mc_kuis.bt_jawaban4.txt_Jawaban.text = acakJawaban[3];
}

 

here the function for the score :

 

this.mc_kuis.bt_jawaban1.on("click",onClickAnswer.bind(this));
this.mc_kuis.bt_jawaban2.on("click",onClickAnswer.bind(this));
this.mc_kuis.bt_jawaban3.on("click",onClickAnswer.bind(this));
this.mc_kuis.bt_jawaban4.on("click",onClickAnswer.bind(this));
function onClickAnswer(e)
{	
if(IsAnswer==true)
	{
		var item=e.currentTarget;
		if(item.name=="jawaban_benar"+currentPertanyaan.jawaban_benar)  
		{
			score+=10;
			this.text_skor.text=score;
			console.log(score);
		}else{
			console.log("Incorrect");
		}
		IsAnswer=false;
	}
	NextQuestion.bind(this)();
	console.log(onClickAnswer);
	
}
function NextQuestion(e)
{
	indexPertanyaan++;
	if(indexPertanyaan == data.length)
	{
		this.gotoAndStop("LB_HasilKuis")	
	}else{
		currentPertanyaan=data[indexPertanyaan];
		loadPertanyaan.bind(this)();
	}
}

 

 When I'm debugging , it's like the button all false or it 's like just a button and the score not increase 
Thank you for Helping me, and sorry confused you all and it seems like I often make discussions because I am still very new and confused. 

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
September 6, 2024

what's the developer console say?

Known Participant
September 7, 2024

 I Try to click the correct answer "Bekam Basah"

and it say inccoret and the score appear 

 When I try to choose incorrect answer it's still false
I think there might be something wrong in the code to randomize the answer or maybe in another function

here code I use for debugging 




Known Participant
September 7, 2024

when the value is false, the score will be increased by 10, and i'm add an alert message 


and the text score is update , but when I answered the other questions, It's like the function not executed. It's like the the function executed for the first question

function onClickAnswer(e)
{	
if(IsAnswer==false)
	{
		var item=e.currentTarget;
		if(item.name=="jawaban_benar"+currentPertanyaan.pilihan_jawaban)  
		{
			score+=10;
			console.log("Correct "+score);
			alert("Benar");
			this.text_skor.text=score;
		}else{
			score+=10;
			console.log("Incorrect "+score);
			alert("Salah");
			this.text_skor.text=score;
		}
		IsAnswer=true;
	}
	NextQuestion.bind(this)();
}


In this experiment, I tried only randomizing the questions and not the answers.
Here the all code :

//variabel global
//create array pertanyaan

var data = [{
	pertanyaan_text: "Berapakah Jenis Bekam",
	jawaban_benar: "2",
	pilihan_jawaban: ["1", "3", "2","4"]
}, {
	pertanyaan_text: "Bekam yang dilakukan dengan memberikan perlukaan disebut",
	jawaban_benar: "1",
	pilihan_jawaban: ["Bekam Kering", "Bekam Basah", "Bekam Luncur","Bekam Pijat"]
}, {
	pertanyaan_text: "Salah satu Kontraindikasi Absolut Bekam adalah",
	jawaban_benar: "0",
	pilihan_jawaban: ["Hemofilia", "Hipertensi", "Anak-anak","Sakit Kepala"]
}, ];

var indexPertanyaan = 0;
var currentPertanyaan;
var score = 0;
var IsAnswer=false;

//Fungsi-Fungsi 

function mixed(Items)
{
	var newArray=[];
	var original= Items.concat();
	while(original.length>0)
	{
	  var r =Math.floor(Math.random()*(original.length));
		newArray.push(original[r]);
		original.splice(r,1);
	}
	return newArray;
}

loadPertanyaan.bind(this)();

function loadPertanyaan(){
//Acak Soal
data= mixed(data);
	
//Ambil soal pertama yang baru
currentPertanyaan = data[indexPertanyaan];
	
//Tampilkan pertanyaan
this.mc_kuis.txt_Pertanyaan.text = currentPertanyaan.pertanyaan_text;
	
//Acak pilihan jawaban dan menampilkan pada button
//var acakJawaban = mixed(currentPertanyaan.pilihan_jawaban);
this.mc_kuis.bt_jawaban1.txt_Jawaban.text = currentPertanyaan.pilihan_jawaban[0];
this.mc_kuis.bt_jawaban2.txt_Jawaban.text = currentPertanyaan.pilihan_jawaban[1];
this.mc_kuis.bt_jawaban3.txt_Jawaban.text = currentPertanyaan.pilihan_jawaban[2];
this.mc_kuis.bt_jawaban4.txt_Jawaban.text = currentPertanyaan.pilihan_jawaban[3];
}

this.mc_kuis.bt_jawaban1.on("click",onClickAnswer.bind(this));
this.mc_kuis.bt_jawaban2.on("click",onClickAnswer.bind(this));
this.mc_kuis.bt_jawaban3.on("click",onClickAnswer.bind(this));
this.mc_kuis.bt_jawaban4.on("click",onClickAnswer.bind(this));

console.log(loadPertanyaan);
console.log(onClickAnswer);

function onClickAnswer(e)
{	
if(IsAnswer==false)
	{
		var item=e.currentTarget;
		if(item.name=="jawaban_benar"+currentPertanyaan.pilihan_jawaban)  
		{
			score+=10;
			console.log("Correct "+score);
			alert("Benar");
			this.text_skor.text=score;
		}else{
			score+=10;
			console.log("Incorrect "+score);
			alert("Salah");
			this.text_skor.text=score;
		}
		IsAnswer=true;
	}
	NextQuestion.bind(this)();
}

function NextQuestion()
{
	indexPertanyaan++;
	if(indexPertanyaan == data.length)
	{
		alert("Selesai")
	}else{
		currentPertanyaan=data[indexPertanyaan];
		loadPertanyaan.bind(this)();
	}
}