# Flip boolean value

**URL:** <https://community.postman.com/t/flip-boolean-value/31619>\
**Category:** Help Hub\
**Created:** [January 17, 2022, 1:56pm UTC](https://community.postman.com/t/flip-boolean-value/31619 "2022-01-17T13:56:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![janeyack](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@janeyack](https://community.postman.com/u/janeyack)\
**Post date:** [January 17, 2022, 1:56pm UTC](https://community.postman.com/t/flip-boolean-value/31619/1 "2022-01-17T13:56:31Z")

</div>

Hi there. How should I write this  
a = !a  
in the ‘Tests’ tab?

Every second request the value of ‘a’ should be changed, but I’m not sure how to properly write it.

---

<div class="post-metadata">

**Author:** ![pranavdavar](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pranavdavar/32/9152_2.png) [@pranavdavar](https://community.postman.com/u/pranavdavar)\
**Post date:** [January 18, 2022, 5:25am UTC](https://community.postman.com/t/flip-boolean-value/31619/2 "2022-01-18T05:25:35Z")

</div>

Hi @janeyack, Welcome to the community!

For such a use case, you may need to use postman variables (global, collection, or environment). For simplicity, below is the test code using global variables for the above use case.

```auto
let a = pm.globals.get("a");
console.log(a);
if (a === true) {
    pm.globals.set("a", false);
}else {
    pm.globals.set("a", true);
}

```

Hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [January 19, 2022, 9:43pm UTC](https://community.postman.com/t/flip-boolean-value/31619/3 "2022-01-19T21:43:14Z")

</div>

Are you iterating over the same request or are you going through multiple requests in a collection? That makes a difference in how this code should be written and where it is written 🙂
