Answer the question
In order to leave comments, you need to log in
How to return a value as a number?
Hello!
I have two constants that return true / false at different screen resolutions:
isMobile - returns true if the window width is less than 992px
isTablet - returns true if the window width is less than 1600px
Linter in the project prohibits the use of triple ternary conditions, etc., then yes it doesn't work
{isMobile ? 'Меньше 992' : isTablet ? 'Меньше 1600, но больше 992' : 'Больше 1600'}
const blockWidth = () => {
if (isMobile) {
return 100;
console.log('Меньше 992');
}
if (isTablet) {
return 150;
console.log('Меньше 1600, но больше 992');
}
return 200;
console.log('Больше 1600');
};
Answer the question
In order to leave comments, you need to log in
Try like this
let isMobile = true;
let isTablet = false;
console.log( ( isMobile ? 'Меньше 992' : (isTablet ? 'Меньше 1600, но больше 992' : 'Больше 1600' ) ) );
const blockWidth = () => {
if (isMobile) {
console.log('Меньше 992');
return 100;
}
if (isTablet) {
console.log('Меньше 1600, но больше 992');
return 150;
}
console.log('Больше 1600');
return 200;
};
let b = blockWidth();
console.log(b);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question