본문 바로가기

Happly Coding10

[CodeWars] 8kyu#5 - Broken Greetings [CodeWars] 8kyu#5 - Broken Greetings ■ Description:Correct this code, so that the greet function returns the expected value. ■ Question:1234567function Person(name){ this.name = name;} Person.prototype.greet = function(otherName){ return "Hi " + otherName + ", my name is " + name;}Colored by Color Scriptercs 솔직히.. 뭘 어떻게 하라는건지.. 했다.이번 문제를 풀기 위해서는 생성자 함수와 프로토타입이란 개념이 필요하다.공부하자!! ■ Solution:1234567.. 2016. 5. 29.
[CodeWars] 8kyu#4 - Square(n) Sum [CodeWars] 8kyu#4 - Square(n) Sum ■ Description:Complete the squareSum method so that it squares each number passed into it and then sums the results together. For example:squareSum([1, 2, 2]); // should return 9 ■ Qustion:function squareSum(numbers){ } ■ My Solution:1234567function squareSum(numbers){ var a = numbers[0]+numbers[1]; var b = numbers[2]; var powReturn =0; powReturn = Math.pow(a,b).. 2016. 5. 28.
[CodeWars] 8kyu#3 - Get Planet Name By ID [CodeWars] 8kyu#3 - Get Planet Name By ID ■ Description:The function is not returning the correct values. Can you figure out why? getPlanetName(3); // should return 'Earth' ■ 문제1234567891011121314151617181920212223function getPlanetName(id){ var name; switch(id){ case 1: name = 'Mercury' case 2: name = 'Venus' case 3: name = 'Earth' case 4: name = 'Mars' case 5: name = 'Jupiter' case 6: name = '.. 2016. 5. 28.
[CodeWars] 8kyu#2 - Return to Sanity [CodeWars] 8kyu#2 - Return to Sanity ■ InstructionsThis function returns something strange. What's wrong? ■ 문제123456function mystery() { var results = {sanity: 'Hello'}; return results;}cs ■ My Solution1234function mystery() { var results = {'sanity': 'Hello'}; return results['sanity'];}Colored by Color Scriptercs ■ 풀이'객체'을 알면 풀린다 > 참고 : 생활코딩 - 자바스크립트 '객체' 2016. 5. 25.