# Using if else statement condition for login test

**URL:** <https://community.postman.com/t/using-if-else-statement-condition-for-login-test/26323>\
**Category:** Help Hub\
**Created:** [July 31, 2021, 2:39am UTC](https://community.postman.com/t/using-if-else-statement-condition-for-login-test/26323 "2021-07-31T02:39:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![science-astronaut-50](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@science-astronaut-50](https://community.postman.com/u/science-astronaut-50)\
**Post date:** [July 31, 2021, 2:39am UTC](https://community.postman.com/t/using-if-else-statement-condition-for-login-test/26323/1 "2021-07-31T02:39:10Z")

</div>

**Your question may already have an answer on the community forum. Please search for related topics, and then read through the [guidelines](https://community.postman.com/t/about-the-just-getting-started-category/37) before creating a new topic.**

> Here’s an outline with best practices for making your inquiry.

_My question_:

_Details (like screenshots)_:  
I am using if else statement condition for login test and try to success value should be in true and should be match msg for all different condition in body value

let jsonData1 = pm.response.json(),

```
msg = ["Login Successfull", 

       "Incorrect Password",

       "Please register first." ]

if (jsonData1.success === "false") {

pm.test("password is wrong"${jsonData1.msg}, () => {

    pm.expect(jsonData1.msg).to.be.oneOf("Incorrect Password")

})

else {

pm.test("Login Successfull" $ {jsonData1.msg}, () => {

    pm.expect(jsonData1.msg).to.equal("Login Successfull")

}

```

}

```
}`

```

_How I found the problem_:  
There was an error in evaluating the test script: SyntaxError: Unexpected token ‘else’

_I’ve already tried_:  
 ![Postman 31-07-2021 08_10_46 (2)](https://us1.discourse-cdn.com/getpostman/original/2X/e/eacdf877c65508d7d3a2f6ef86b8ff66b0ab0ac1.png)

---

<div class="post-metadata">

**Author:** ![ianb120](https://avatars.discourse-cdn.com/v4/letter/i/f14d63/32.png) [@ianb120](https://community.postman.com/u/ianb120)\
**Post date:** [July 31, 2021, 1:22pm UTC](https://community.postman.com/t/using-if-else-statement-condition-for-login-test/26323/2 "2021-07-31T13:22:23Z")

</div>

Hi @science-astronaut-50,

I got rid of the red line errors you were seeing on the code. I’ve also cleaned it up with missing semi-colons and indentations. Hopefully this helps 🙂

```auto
msg = ["Login Successfull",
       "Incorrect Password",
       "Please register first." ];

if (jsonData1.success === "false") {
    // use backticks to when adding a object in a string
    pm.test(`password is wrong ${jsonData1.msg}`, () => {
        pm.expect(jsonData1.msg).to.be.oneOf("Incorrect Password");
    })

//missing closing bracket
} else {

    // use backticks to when adding a object in a string
    pm.test(`Login Successfull ${jsonData1.msg}`, () => {
        pm.expect(jsonData1.msg).to.equal("Login Successfull");
    
    //missing closing bracket on the closing test
    })
}

```
