FED55. 流程控制
描述
实现 fizzBuzz 函数,参数 num 与返回值的关系如下:示例1
输入:
15
输出:
fizzbuzz
HTML/CSS/JavaScript 解法, 执行用时: 876ms, 内存消耗: 77876KB, 提交时间: 2020-12-28
{"css":"","js":"function fizzBuzz(num) {\nif (num % 3 === 0 && num % 5 === 0){\n return 'fizzbuzz'\n} else if (num % 3 === 0){\n return 'fizz'\n} else if (num % 5 === 0){\n return 'buzz'\n} else if (num === null || typeof(num) !== 'number'){\n return false\n} else {\n return num\n}\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 877ms, 内存消耗: 77864KB, 提交时间: 2020-12-12
{"css":"","js":"function fizzBuzz(num) {\nif (num % 3 === 0 && num % 5 === 0){\n return 'fizzbuzz'\n} else if (num % 3 === 0 && num % 5 !== 0){\n return 'fizz'\n} else if (num % 5 === 0 && num % 3 !== 0 ){\n return 'buzz'\n} else if (num === null || typeof(num) !== 'number'){\n return false \n} else {\n return num \n}\n}\nfizzBuzz(15);","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 877ms, 内存消耗: 77868KB, 提交时间: 2020-12-25
{"css":"","js":"function fizzBuzz(num) {\n let res = ''\n if(typeof num !== 'number') {\n return false\n }\n res = (num % 5 === 0 && num % 3 === 0) ? 'fizzbuzz' : (num % 5 === 0) ? 'buzz' : (num % 3 === 0) ? 'fizz' : num\n return res \n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 878ms, 内存消耗: 77856KB, 提交时间: 2020-12-28
{"css":"","js":"function fizzBuzz(num) {\n if(num%3==0 && num%5==0){\n return 'fizzbuzz';\n }else if(num%3==0){\n return 'fizz';\n }else if(num%5==0){\n return 'buzz';\n }else if(!num || Object.prototype.toString.call(num) !== '[object Number]'){\n return false;\n }else{\n return num;\n }\n}","html":"","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 880ms, 内存消耗: 77872KB, 提交时间: 2020-12-05
{"css":"","js":"function fizzBuzz(num) {\n if(typeof(num) == \"number\"){\n if(num%3===0 && num%5===0){\n return \"fizzbuzz\"\n }else if(num%3 === 0){\n return \"fizz\"\n }else if(num%5===0){\n return \"buzz\"\n }else{\n return num\n }\n }else{\n return false\n }\n \n}","html":"","libs":[]}