It's time for your first solo assignment since joining the Flatbook team!
Here at Flatbook HQ, we're a bit overwhelmed by all of the user data we've been collecting, and we need some help crunching the numbers.
There are three challenges we need you to solve. Code your solution in
index.js
. We'll provide some brief instructions here, but you should really
rely on the test failure messages to guide your code.
-
When we started out, we assigned ID numbers sequentially to new users, so our first user ID is
1
, second is2
, third is3
, and so on. That was fine when we were a fledgling company, but, now that we have millions of active users, it would be easier if all of our user IDs were the same length. We'd like the IDs to start from1000000001
(one billion and one) instead of1
. Create a variable namednewID
that adds1000000000
to the value inoldID
. Don't defineoldID
— assume the system already knows what it is just by using that variable name. -
During the sign-up process, we require new users to provide their age. However,the junior developer tasked with creating the sign-up form forgot to validate that the user had entered an integer, so we have a lot of accounts floating around with weird ages like
21.7
or9.5
. We'd like you to help us identify which users need to be prompted to reenter their age. Create a variable namedageIsValid
that checks whether the value incurrentAge
is a valid integer. You don't have to definecurrentAge
— the system will take care of that part. -
Finally, we need a way to randomly select a user by their ID number. As you know, we have millions of active users, but since this is your first assignment we'll limit the testing pool to twenty users with IDs between
1000000001
and1000000020
. You're tasked with creating three variables:
randomNumber
, which should contain a randomly-generated number between0
(inclusive) and20
(exclusive).randomInteger
, which should take the value inrandomNumber
and round it down to the nearest integer.randomUserID
, which should convertrandomInteger
into a valid ID number — an integer between1000000001
and1000000020
.
View Arithmetic Lab on Learn.co and start learning to code for free.