switch (조건) {
case 값1:
break
case 값2:
break
default:
}
function price(fruit) {
let p
switch (fruit) {
case 'Apple':
p = 1000
break
case 'Banana':
p = 1500
break
case 'Cherry':
p = 2000
break
default:
p = 0
}
return p
}
console.log(price('Apple'));
console.log(price('Banana'));
console.log(price('Cherry'));
console.log(price('Hello'));
function price(fruit) {
switch (fruit) {
case 'Apple':
return 1000
case 'Banana':
return 1500
case 'Cherry':
return 2000
default:
return 0
}
}
console.log(price('Apple'));
console.log(price('Banana'));
console.log(price('Cherry'));
console.log(price('Hello'));