Can't make multiplication

Hi,

Im trying to show the result of the following multiplication

$w("#rgbresults").text = String(Number(correct_answers) * 2);

But it won’t work. Can someone please help me?

Hi,
The code looks ok, Where do you place this code ?
Roi

Yeah maybe the problem is in the rest of the code:

import wixWindow from 'wix-window';

$w.onReady(function () {

});

export function button56_click(event, $w) {
	let correct_answers = 0;
	if ($w("#a1").selectedIndex === 2) {
		correct_answers = (Number(correct_answers) + 1);
	} else {
		correct_answers = (Number(correct_answers) - 1);
	}

	if ($w("#a1").selectedIndex === 3) {
		correct_answers = (Number(correct_answers) + 1);
	} else {
		correct_answers = (Number(correct_answers) - 1);
	}

	if ($w("#a1").selectedIndex === 0) {
		correct_answers = (Number(correct_answers) + 1);
	} else {
		correct_answers = (Number(correct_answers) - 1);
	}

	if ($w("#a1").selectedIndex === 2) {
		correct_answers = (Number(correct_answers) + 1);
	} else {
		correct_answers = (Number(correct_answers) - 1);
	}

	if (Number(correct_answers) < 3) {
		$w("#rbtitle").text = "Você finalizou o Quiz";
	} else {
		$w("#rbtitle").text = "Parabéns!";
	}

	if (Number(correct_answers) < 0) {
		$w("#rgbresults").text = "Você acertou 0 de 4 perguntas. " + "A sua recompensa: 0,00 C";
	} else {
		$w("#rgbresults").text = "Você acertou " + String(correct_answers) + " de 4 perguntas. " + "A sua recompensa: " + String(Number(correct_answers) * 2) + ",00 C";
	}

	$w("#quizbox").hide();
	$w("#resultsbox").show();
	wixWindow.scrollTo(0, 0);
}

Hi there. What if you’ld say ‘let correct_answers = 0’, thus keep it, then just do ‘correct_answers = correct_answers + 1’ or ‘correct_answers - 1’ and at the end do ‘correct_answers.toString()’. Saves you code :slight_smile:

It didn’t work :frowning:

I would instead of let use var so you can count, calculate and do all that without having to convert on every line with Number().
var correct_answers = 0;

Lol I just figured it out, the problem was that I used only “#a1” and forgot the “#a2” and so on…