jeudi 10 septembre 2020

Error while using if statement inside Map reactJS

I am new to reactJS. I am implementing a Quiz page, where users can answer the questions and once they submit answers, the result is displayed. Following is the DisplayResult component which calculates the score and displays the result. I am getting error at the if statement. Checked the syntax multiple times, not sure if it is a syntax issue or if I am missing something. Could you please help.

import React from "react";
function DisplayResult(props) {
var score=0;
var Answers=[1947,1950];
props.data.map((dat, i) => 
    ({if (dat===Answers[i]) {score++}}
    ));
return<div>Your answers are {props.data[0]}, {props.data[1]} and your score is {score} </div>;

}
export default DisplayResult;

Below is the error I am getting: ./src/DisplayResult.jsx Line 8:14: Parsing error: Unexpected token, expected ","

6 | var Answers=[1947,1950]; 7 | props.data.map((dat, i) =>

8 | ({if (dat===Answers[i]) {score++}} | ^ 9 | )); 10 | returnYour answers are {props.data[0]}, {props.data[1]} and your score is {score} ;

Aucun commentaire:

Enregistrer un commentaire