Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ages(age) {
- if(age > 65){
- console.log('elder');
- }
- else if(age > 19){
- console.log('adult');
- }
- else if(age > 13){
- console.log('teenager');
- }
- else if(age > 2){
- console.log('child');
- }
- else if(age >= 0){
- console.log('baby');
- }
- else{
- console.log('out of bounds');
- }
- }
- Решение с тернарен оператор:
- function ages(age) {
- let personStatus =
- age > 65? 'elder':
- age > 19? 'adult':
- age > 13? 'teenager':
- age > 2? 'child':
- age >= 0? 'baby' : 'out of bounds';
- console.log(personStatus);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement