Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do i display varible data as text

I can't seem to get my message display

This is my code

import * as document from "document";

const myaLabel = document.getElementById("myaLabel");

function Random() {
return Math.floor((Math.random() * 1) + 1);
}

function getRandom() {
var x = Random();

if (x === 1) {x = "Fool of a Took!";}

myaLabel.text(x)
}

Best Answer
0 Votes
3 REPLIES 3

sorry the code actually is

import * as document from "document";
const myaLabel = document.getElementById("myaLabel");
function Random() {
return Math.floor((Math.random() * 1) + 1);
function getRandom() {
var X = Random();
if (X === 1) {X = "Fool of a Took!";} else {X = "Umuh"}
function getX()
myaLabel.text = `${X}`
}
}

Best Answer
0 Votes

It's a bit hard to tell because the {} seem to be mismatched. You seem to be declaring functions but never executing them.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

I've written an example, similar to your approach. The way you get your random number it always will be 1, so I changed from Math.floor to Math.round
You also could just easily assign the text inside the if without the need of any function, but here we go...

 

 

function random() {
	return  Math.round(Math.random()) + 1;
};

function getRandom() {
let x = random();

if (x === 1) {
	x = "Fool of a Took!"
} else {
	x = "Umuh"
}
	return x;
}
console.log(getRandom());// or label.text = getRandom()

 

 

Best Answer