Need help continuing a function in java in appstudio

35 Views Asked by At

i have a set of radio buttons, each holding a number as their value (odd/even) and upon clicking a button an output is shown in a label and have managed to do that much, but now i am not sure how to reference the value of the button to output in the label this message:'mary the number [number] is [odd/even]'

1

this image shows this code:

let num1 = 176
let num2 = 345
let num3 = 1037
let num4 = 3421
let num5 = 2289
let num6 = 3044
     
rdoOddEven.onclick=function(){
if Number($"input[name=rdoOddEven]:checked").prop("value")%2==0
  lblOddEven.className=''
  lblOddEven.style.color='black'
  lblOddEven.value = `Mary, the number ${$("input[name=rdoOddEven]:checked").prop("value")} is even`
else if Number($"input[name=rdoOddEven]:checked").prop("value")%2==1
  lblOddEven.className=''
  lblOddEven.style.color='black'
  lblOddEven.value = `Mary, the number ${$("input[name=rdoOddEven]:checked").prop("value")} is odd`
}
1

There are 1 best solutions below

0
Diego Ferruchelli On

First of all, check your syntax. JavaScript follows the core syntax of the C language. The if construct requires that you enclose the whole expression to be evaluated between (). And when you need to conditionally execute several lines, you must enclose them between {}.

You may compare this code with yours.

let num1 = 176
let num2 = 345
let num3 = 1037
let num4 = 3421
let num5 = 2289
let num6 = 3044
     
rdoOddEven.onclick=function() {
  if (Number($"input[name=rdoOddEven]:checked").prop("value")%2==0) {
    lblOddEven.className=''
    lblOddEven.style.color='black'
    lblOddEven.value = `Mary, the number ${$("input[name=rdoOddEven]:checked").prop("value")} is even`
  }
  else if (Number($"input[name=rdoOddEven]:checked").prop("value")%2==1) {
    lblOddEven.className=''
    lblOddEven.style.color='black'
    lblOddEven.value = `Mary, the number ${$("input[name=rdoOddEven]:checked").prop("value")} is odd`
  }
}