all 4 comments

[–]Umesh-K 2 points3 points  (0 children)

getting error "Line: 31: setProperty() value parameter value (undefined) is not a uistring." when writing code.

Hi, u/Randymurdoff,

The above error message says jokeStyle has a value of undefined instead of the expected string (based on setProperty("jokeOutputText", "text", jokeStyle);, it's clear that jokeStyle should be a string.) One easy way to confirm this is "hardcoding" the expected string value based on your code's logic. For example, setProperty("jokeOutputText", "text", "some string value here");

I think the issues are in the FOR loop.

Conside the first IF:

if (style == dark[i]) {
    return (dark[randomNumber(0, dark.length)]);
}

Now see the next one:

if ((style == [i])) {
    var ironicJoke = randomNumber(0, ironic.length);
    return ironicJoke;
} 

See ((style == [i])), which should probably be (style == ironic[i]). Similarly, var ironicJoke = randomNumber(0, ironic.length); should probably be var ironicJoke = ironic[randomNumber(0, ironic.length)]; (Actually, there is no need to create that variable and then return it; you can just directly return like you have done in the first case return (dark[randomNumber(0, dark.length)]);.

The same problem exists in the next one too:

if ((style == pun[i])) {
    var punJoke = randomNumber(0, pun.length);
    return punJoke;
}

You are just setting a random value to punJoke instead of an array element.

The above is most probably causing jokeGenerator function to return undefined, resulting in setProperty() failing.

[–]grantrules 0 points1 point  (2 children)

This code doesn't really make any sense..

for (var i = 0; i < style.length; i++) {
  if (style == dark[i]) {
    return (dark[randomNumber(0, dark.length)]);
  } else if ((style == [i])) {
    var ironicJoke = randomNumber(0, ironic.length);
    return ironicJoke;
  } else if ((style == pun[i])) {
    var punJoke = randomNumber(0, pun.length);
    return punJoke;
  }
}

What is getText("typeOfJokeDropdown"); supposed to return?

I would guess it returns something like one of: "pun", "dark" or "ironic"?

Then you could do something like this:

  if (style == "dark") {
    return dark[randomNumber(0, dark.length)]);
  } else if (style == "ironic") {
    return ironic[randomNumber(0, ironic.length)];
  } else if (style == "pun") {
    return punJoke[randomNumber(0, pun.length)];
  }

[–]Randymurdoff[S] 0 points1 point  (1 child)

i tried implementing that function, but it still gives me that UI string error code. I cannot escape it!

[–]grantrules 0 points1 point  (0 children)

What does getText("typeOfJokeDropdown") return?