# Can I make a back button in app lab?

**URL:** <https://forum.code.org/t/can-i-make-a-back-button-in-app-lab/38676>\
**Category:** Uncategorized\
**Tags:** csd-unit-4\
**Created:** [November 14, 2023, 3:13pm UTC](https://forum.code.org/t/can-i-make-a-back-button-in-app-lab/38676 "2023-11-14T15:13:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![emichael](https://avatars.discourse-cdn.com/v4/letter/e/e19b73/32.png) [@emichael](https://forum.code.org/u/emichael)\
**Post date:** [November 14, 2023, 3:13pm UTC](https://forum.code.org/t/can-i-make-a-back-button-in-app-lab/38676/1 "2023-11-14T15:13:38Z")

</div>

My students are successfully using setScreen to move from one screen to another. However, they want to use a back button to return to whichever screen the user just came from. Does anyone know how to do this?

Thanks!

---

<div class="post-metadata">

**Author:** ![varrience](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/varrience/32/8042_2.png) [@varrience](https://forum.code.org/u/varrience)\
**Post date:** [November 15, 2023, 8:26am UTC](https://forum.code.org/t/can-i-make-a-back-button-in-app-lab/38676/2 "2023-11-15T08:26:40Z")

</div>

so… this may be more complicated depending on how many screens your students may have but storing the screen name in a variable should do the trick

```auto
var currentScreen = "screen1"
var previousScreen = "";
function changeScreen(id) {
previousScreen = currentScreen;
setScreen(id);
currentScreen = id;
}

```

though if your students are looking for something further back like tracing paths you took through multiple screens you’ll need to do a big lesson for that and I’m not even sure if you should. this should just help get there feet wet to get a feel for it either that or setting back buttons on each screen of which you’ll pretty much need anyways using `setScreen(id)`will allow screen navigation in your program

---

<div class="post-metadata">

**Author:** ![cloliver2018](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@cloliver2018](https://forum.code.org/u/cloliver2018)\
**Post date:** [April 21, 2025, 8:49pm UTC](https://forum.code.org/t/can-i-make-a-back-button-in-app-lab/38676/3 "2025-04-21T20:49:12Z")

</div>

// Assuming you have screens named “screen1”, “screen2”, “screen3”, etc.

var currentScreen = “screen1”;

function navigateToScreen(screenId) {  
// Update the current screen ID before changing to the new screen  
currentScreen = screenId;  
setScreen(screenId);  
}

// Attach the function to the click event of the “previous” button.  
// You can use the same function for all “previous” buttons.  
onEvent(“btnPrevious”, “click”, function() {  
// In this example, we’re always going back to the previous screen.  
navigateToScreen(currentScreen);  
});
