Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
Ask about switch/case
let rachunek = prompt('Podaj cene rachunku');
    
switch(rachunek) {
    case rachunek >=50 && rachunek <= 300:
        console.log('Cena rachunku wynosi ' + rachunek + ' zł ' + 'natomiast napiwek wynosi' + rachunek * 0,15 + ' zł');
        break;

    case rachunek < 50 && rachunek > 300:
        console.log('Cena rachunku wynosi ' + rachunek + ' zł ' +'natomiast napiwek wynosi' + rachunek * 0,2 + ' zł');
        break;

    default:
        console.log('Złe dane');
}

I don't know what's wrong, because terminal always shows me only 2 zł tip.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

let rachunek = prompt('Podaj cene rachunku');

switch(true) {
case rachunek.length >=50 && rachunek.length <= 300:
    console.log('Cena rachunku wynosi ' + rachunek + ' zł ' + 'natomiast napiwek wynosi' + rachunek * 0,15 + ' zł');
    break;
case rachunek.length < 50 && rachunek.length > 300:
    console.log('Cena rachunku wynosi ' + rachunek + ' zł ' +'natomiast napiwek wynosi' + rachunek * 0,2 + ' zł');
    break;
default:
    console.log('Złe dane');
}

Your switch expression must be true event check your length string please

let rachunek = prompt('Podaj cene rachunku');

switch(true) {
case rachunek.length >=50 && rachunek.length <= 300:
    console.log('Cena rachunku wynosi ' + rachunek + ' zł ' + 'natomiast napiwek wynosi' + rachunek * 0,15 + ' zł');
    break;
case rachunek.length < 50 && rachunek.length > 300:
    console.log('Cena rachunku wynosi ' + rachunek + ' zł ' +'natomiast napiwek wynosi' + rachunek * 0,2 + ' zł');
    break;
default:
    console.log('Złe dane');
}
about 4 years ago · Juan Pablo Isaza Report

0

Switch doesn't calculate, just compare. if should be used to calculate.

let rachunek = prompt('Podaj cene rachunku');
 
    if( parseInt(rachunek) >=50 && parseInt(rachunek) <= 300){
        console.log('Cena rachunku wynosi ' + rachunek + ' zł ' + 'natomiast napiwek wynosi' + rachunek * 0,15 + ' zł');
        }
       else if (parseInt(rachunek) < 50 && parseInt(rachunek) > 300){
        console.log('Cena rachunku wynosi ' + rachunek + ' zł ' +'natomiast napiwek wynosi' + rachunek * 0,2 + ' zł');
        } else {
         console.log('Złe dane');
        }
      

  
 

Here is the logic use of switch.

let result = "0"
if( parseInt(rachunek) >=50 && parseInt(rachunek) <= 300){
       result = "between50and300";
        }
       else if (parseInt(rachunek) < 50 && parseInt(rachunek) > 300){
         result = "notbetween50and300";
        } else {
         result = "default";
        }
switch(result) {
    case "between50and300":
        console.log('Cena rachunku wynosi ' + rachunek + ' zł ' + 'natomiast napiwek wynosi' + rachunek * 0,15 + ' zł');
        break;

    case "notbetween50and300":
        console.log('Cena rachunku wynosi ' + rachunek + ' zł ' +'natomiast napiwek wynosi' + rachunek * 0,2 + ' zł');
        break;

    default:
        console.log('Złe dane');
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!