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 Answersorry 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 AnswerIt's a bit hard to tell because the {} seem to be mismatched. You seem to be declaring functions but never executing them.
Best AnswerI'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()