【发布时间】:2021-09-27 10:01:11
【问题描述】:
任务说明 您在本活动中的任务是创建一个名为 isString 的函数,该函数接受三个参数(a、b、c)。此函数执行以下操作: 它使用 typeof 运算符和严格相等比较来检查所有三个参数 a、b 和 c 的类型是否为字符串。 如果每个参数都是字符串,则返回消息字符串。 如果三个参数中的任何一个不是字符串,则返回消息不是字符串
我不确定如何创建名为 isString 的函数,然后在其下放置三个参数。 我也不确定如何使用 typeof 运算符来完成比较。需要更多详细信息。
/*
Follow the instructions - Create a function called "isString" that takes 3 arguments (x1, x2, x3)
- check if each argument is a string using typeof.
- If each argument is a string, return "strings"
- If each argument is NOT a string, return "not strings"
*/
//Write your code here
////////////////////////////////////////
////////////////////////////////////////
//open the browser console to check results
console.log('results: ', isString('a', 'b', 'c'));
//don't change this line
if (typeof module !== 'undefined') {
module.exports = isString;
}
【问题讨论】:
-
您应该首先确保您提出的问题是正确的。你可以问这样的问题:如何使用 typeof 运算符来检查参数是否为字符串?
标签: javascript string function typeof strict