https://www.codewars.com/kata/571f1eb77e8954a812000837
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
In javascript, Object is one of basic data types. Define an Object can use var obj=new Object() or var obj={}
You can define the object attributes during initialization, like this:
var animal={name:"dog"}
you can also set/get some properties after the object definition, like this:
var animal={}
animal.name="dog" (or animal["name"]="dog")
Task
Give you a function animal, accept 1 parameter:obj like this:
{name:"dog",legs:4,color:"white"}
and return a string like this:
"This white dog has 4 legs."
When you have finished the work, click "Run Tests" to see if your code is working properly.
In the end, click "Submit" to submit your code pass this kata.
코드
function animal(obj){
return `This ${obj.color} ${obj.name} has ${obj.legs} legs.`;
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Return the day (8 kyu) / JavaScript (0) | 2023.04.10 |
---|---|
[Codewars] Is it a palindrome? (8 kyu) / JavaScript (0) | 2023.04.09 |
[Codewars] Grasshopper - Function syntax debugging (8 kyu) / JavaScript (0) | 2023.04.07 |
[Codewars] Anagram Detection (7 kyu) / JavaScript (0) | 2023.04.06 |
[Codewars] Sum of angles (7 kyu) / JavaScript (0) | 2023.04.05 |
댓글