Coding Challenge

Practice a coding challenge in Python and React while using Transcrypt.

Problem statement

Currently our application takes input and shows it in an alert() dialog box. With the way we are using the module as a bridge between Python and JavaScript, it becomes easy to make more JavaScript functions available to our pure Python modules.

For this code challenge, instead of just showing an alert(), we are going to add a confirmation prompt instead. This will either return True or False depending on whether “OK” or “Cancel” was clicked in the confirmation.

Starting with, add a Python reference for the JavaScript window.confirm() function similar to how we added the one for alert().

Next, update the import statement and modify the handleSubmit() function in to show the confirm box instead of the alert. Change the displayed message to ask if the item should be added or not. Display the result of the confirm dialog in the web browser only when the user selects “OK” in the dialog box. Otherwise, the input should be discarded.

Get hands-on with 1200+ tech skills courses.