Purpose: This activity helps you get familiar with creating if statements and loops by tasking you with using them in the random data generator.
Introduction: We want to be able to create lots of different test data quickly that doesn’t require a lot of copy and pasting as well as put some logic into our codebase around the total price random generator. So for this activity we’re going to use if statements and loops.
For this activity, you can either use your existing random data generator code you’ve created or you can use this example code-base.
Activity: Using loops, update your current random data generator code-base to:
Call the data creation function in a loop
Update the random price function with a loop and an if statement to make sure it returns an integer above 100
If you need help, post questions on this thread for support.
when updating the price function, do we NEED to include an IF statement? for this one I have included a WHILE number <= 100 then increment if under 100. which seems to fulfil the criteria.
I’m struggling to figure how to just run the function again IF the result is <= 100 but hurting my brain haha
the trouble is with this is that everything below 100 on the initial function, then becomes 101. I assuming the purpose of the activity is to just run the function again but maybe I’m over complicating it!
You’re correct. You basically want to keep looping until your totalRoomPrice is less than 100. So rather than look at adding or subtracting from totalRoomPrice you could simply keep creating new values for totalRoomPrice until it matches the criteria you want.