Sulayman A.

asked • 09/15/16

Movies Lab

MOVIE LAB
According to the description of R-rated films: Children under 17 require an accompanying parent or adult guardian (age 21 or older) and adults 25 years and under must show ID. And children under the age of 6 are not allowed in after 6:00pm.
Deadpool is an R-rated movie.
Write a JavaScript function named canIWatch that will take age as a parameter.
If the age is less than 6, return You are not allowed to watch Deadpool after 6.00pm.
If the age is 6 or more but less than 17, return You must be accompanied by a guardian who is 21 or older.
If the age is 17 or more but less than 25, return You are allowed to watch Deadpool, right after you show some ID.
If the age is 25 or greater, return Yay! You can watch Deadpool with no strings attached!.
If the age is invalid, return Invalid age.

TEST QUESTION:5
describe('canIWatch tests', function () {
it('Should return the appropriate message for age less than 6', function () {
expect(canIWatch(5)).toEqual('You are not allowed to watch Deadpool after 6.00pm.');
});

it('Should return the appropriate message for age less than 17', function () {
expect(canIWatch(15)).toEqual('You must be accompanied by a guardian who is 21 or older.');
});

it('Should return the appropriate message for age less than 25', function () {
expect(canIWatch(20)).toEqual('You are allowed to watch Deadpool, right after you show some ID.');
});

it('Should return the appropriate message for age above 25 than 6', function () {
expect(canIWatch(30)).toEqual('Yay! You can watch Deadpool with no strings attached!');
});

it('should return an appropriate message if provided age is invalid', function () {
expect(canIWatch(-1)).toEqual('Invalid age.');
});
});

1 Expert Answer

By:

James G. answered • 07/30/17

Tutor
4.9 (1,012)

Skilled at programming and problem solving

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.