Вы попали на английскую версию сайта. Большая часть курсов доступна на русском языке

Happy ticket Course Challenge: Intro to Programming

A happy ticket is a ticket with such a serial number that the sum of the first three digits is the same as the sume of the last three digits.

For example, ticket number 385916 is a happy ticket, since 3 + 8 + 5 = 9 + 1 + 6

isHappyTicket.js

Implement and export as default a function that verifies the happiness of a ticket. This function should return true if the ticket is happy, and false otherwise.

isHappyTicket(385916); // true
isHappyTicket(231002); // false
isHappyTicket(128722); // true

Hints

Convert a number to string using String like so:

String(1234); // "1234"

Convert a string back into a number using Number like so:

Number("456"); // 456

Use the length value to find out the length of a string:

'welcome'.length; // 7

Use the substr method to get a substring:

'foo'.substr(1, 2); // 'oo';
Successful completion: 96%

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, the opportunity to seek help from mentors and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
115
courses
892
exercises
2241
hours of theory
3196
tests