简体   繁体   English

Odin 项目的任务是使 function ‘大写’,我不知道我的回答是否合适?

[英]Odin project's task to make a function 'capitalize' and I have no idea if my answer is any good?

So I've been doing the Odin Project and I'm at functions right now and there's a task "Write a function called capitalize that takes a string and returns that string with only the first letter capitalized. Make sure that it can take strings that are lowercase, UPPERCASE or BoTh."所以我一直在做 Odin 项目,我现在正在做函数,有一个任务“写一个 function 调用大写,它接受一个字符串并返回该字符串,只有第一个字母大写。确保它可以接受字符串是小写、大写或两者兼而有之。”

 <script> function capitalize(myName, myNameUpper, myNameRan) { const toUpper = "Bartek"; myName = "bartek"; myNameUpper = "BARTEK"; myNameRan = "BaRtEk"; myName, myNameUpper, myNameRan = toUpper; console.log(myName, myNameUpper, myNameRan) } capitalize(); </script>

Is my function any good?我的function好用吗? Thanks in advance for help.在此先感谢您的帮助。

<script>
     

     function capitalize(lowercase,uppercase,both ) {
     const capitalizeLower = lowercase.charAt(0).toUpperCase() + lowercase.slice(1).toLowerCase();
     const capitalizeUpper = uppercase.charAt(0).toUpperCase() + uppercase.slice(1).toLowerCase();
     const capitalizeBoth = both.charAt(0).toUpperCase() + both.slice(1).toLowerCase();
     console.log(capitalizeLower, capitalizeUpper , capitalizeBoth)
     return `${capitalizeLower} ${capitalizeUpper} ${capitalizeBoth}`
     }

     capitalize("hello","HELLO","hEllO");
    
    
     
      </script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试将我的答案从JS转换为Odin项目的Ruby - Trying to translate my answer from JS to Ruby for The Odin Project 我不知道为什么我的 min function 不工作它一直给我 0 作为答案 - I have no Idea why is my min function not working it keeps on giving me 0 as an answer 努力遍历函数并为 Odin Project Rock, Paper, Scissors 返回正确的结果。 我的代码有什么问题? - Struggling to loop through function and return proper results for Odin Project Rock, Paper, Scissors. What's wrong with my code? 在使用 javascript(奥丁项目)赢得 5 次胜利后,如何让我的剪刀石头布游戏重置? - How do I get my rock paper scissors game to reset after 5 wins with javascript (The Odin Project)? 我正在做一个打字稿项目,我试图让我的编辑按钮“编辑”我选择的行。 但我不知道该怎么做 - I am doing a typescript project and I am trying to make my edit button to “edit” the row that I have selected. But I have no idea on how to do it 我的代码有问题吗? 我认为一切都很好 - Is there any problem with my code? I think there's all good Javascript如果/否则不起作用。 奥丁项目的石头,纸,剪刀 - Javascript if/else not working. Odin project's Rock, paper, scissors Odin 项目 TDD 解决方案 - The Odin Project TDD solution Odin 项目中的重复字符串 - repeatString in Odin Project Backbonejs是在另一个函数中调用集合的fetch方法的好主意吗? 如果没有,我应该怎么用? - Backbonejs is calling collection's fetch method in another function good idea? If not what should i use?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM