• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Sep 06, 2024 Sep 06, 2024

Copy link to clipboard

Copied

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. 

TOPICS
Code , Error , How to , Other

Views

108

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 06, 2024 Sep 06, 2024

Copy link to clipboard

Copied

what's the developer console say?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 07, 2024 Sep 07, 2024

Copy link to clipboard

Copied

1.png

 I Try to click the correct answer "Bekam Basah"

2.png

and it say inccoret and the score appear 

3.png

 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

4.png

here code I use for debugging 




Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 07, 2024 Sep 07, 2024

Copy link to clipboard

Copied

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

new1.png

new2.png

new3.png


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)();
	}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2024 Sep 08, 2024

Copy link to clipboard

Copied

LATEST

use console.log to see what's being assessed in the problematic function

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines