【发布时间】:2020-11-18 03:46:17
【问题描述】:
我正在努力解决 TypeScript 中的一个问题,我想知道是否有人可以帮助我。 任何人都可以帮忙吗?我目前正在学习 TypeScript,最初想到的是使用 if/else 语句或 switch 语句。
问题:完成接受布尔值的方法,如果为真则返回“YES”,如果为假则返回“NO”。
export const boolToWord = (bool: boolean): string => {
throw new Error("Not implemented!");
};
这是我想出的第一个解决方案是使用 if/else 语句,但它不起作用。
export const boolToWord = (bool: boolean): string => {
if(true){
return "Yes"
} else if (false) {
return "No"
} else if {
return "Not Implemented"
}
};
boolToWord(True);
我也尝试过使用 switch 语句,但是没有用。
export const boolToWord = (bool: boolean): string => {
switch(boolean){
case: true;
console.log("YES");
break;
case: false;
console.log("NO");
break;
case: error;
console.log("Not Implemented")
break;
}
};
boolToWord(True);
【问题讨论】:
标签: string typescript boolean