10-17-2022 08:47
10-17-2022 08:47
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)
}
10-17-2022 10:45
10-17-2022 10:45
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}`
}
}
10-17-2022 12:46
10-17-2022 12:46
It's a bit hard to tell because the {} seem to be mismatched. You seem to be declaring functions but never executing them.
10-17-2022 13:05 - edited 10-17-2022 13:48
10-17-2022 13:05 - edited 10-17-2022 13:48
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()