Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add program #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor: put zero case in the beginning
tkornilova committed Jun 27, 2022
commit c30fbe675ea7c492ef9f9a0a6fca9695f6a05804
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -39,10 +39,10 @@ module.exports = function toReadable (num) {
90: 'ninety',
}

if (hundredsRounded > 0 && tens === 0 && ones === 0) {
return resultFinal = `${numbers[hundredsRounded]} hundred`;
} else if (hundredsRounded === 0 && tens === 0 && ones === 0) {
if (hundredsRounded === 0 && tens === 0 && ones === 0) {
return resultFinal = `zero`;
} else if (hundredsRounded > 0 && tens === 0 && ones === 0) {
return resultFinal = `${numbers[hundredsRounded]} hundred`;
} else if (hundredsRounded > 0 && (tens > 0 || ones > 0)) {
result = `${numbers[hundredsRounded]} hundred`;
}
@@ -53,7 +53,7 @@ module.exports = function toReadable (num) {
resultFinal = `${result} ${numbers[(tensRounded * 10)]}`;
} else if ((tens * 10) < 20 && tens > 0) {
resultFinal = `${result} ${numbers[tens * 10]}`;
} else if (tens = 0 && ones !==0) {
} else if (tens === 0 && ones !== 0) {
resultFinal = `${numbers[ones]}`;
}