0

Overview: I just started learning react and I want to create a where, after the "Submit" button is pressed I get an alert with the monthly income * 2 (Calc() function). However when I writhe the Calc() function I geht a parsing error and the msg that I am missing a semicolon. I am not sure why that is appearing since the missinge semicolon is in the same line where my ' Calc() { ' code is and I never heard that at the start of a fucntiona semicolon is required.

Error msg: Error msg

Code below:

    export function Parttime(){

    const [monthly_income, setMonthly_income] = useState('');

//Error in same line where Calc() //

    Calc(){
        a = {monthly_income} * 2
        alert("Your monthly income times 2 is:", {a})
    }

//code continues after return( //

   return (

Screenshot of Error msg:

Julius
  • 1
  • 3
  • Check your function declaration. Your code will also fail at `a = {monthly_income}*2` since the variable isn't initialized. Looks like you are also using JSX in a javascript function with `monthly_income` – fynmnx Jun 28 '21 at 16:44

1 Answers1

1

Declare the function as arrow function

const Calc = () => {
// Your code
}
moshfiqrony
  • 4,303
  • 2
  • 20
  • 29