Create a function which answers the question "Are you playing banjo?".
If your name starts with the letter "R" or lower case "r", you are playing banjo!
The function takes a name as its only argument, and returns one of the following strings:
name + " plays banjo"
name + " does not play banjo"
Names given are always valid strings.
function areYouPlayingBanjo(name) {
return name[0] === 'R' || name[0] === 'r' ? `${name} plays banjo` : `${name} does not play banjo` ;
}
function areYouPlayingBanjo(name) {
return name + (name[0].toLowerCase() == 'r' ? ' plays' : ' does not play') + " banjo";
}
function areYouPlayingBanjo(name) {
if (name[0].toLowerCase() === 'r') {
return name + ' plays banjo';
} else {
return name + ' does not play banjo';
}
}
You are given two interior angles (in degrees) of a triangle.
Write a function to return the 3rd.
Note: only positive integers will be tested.
https://en.wikipedia.org/wiki/Triangle
function otherAngle(a, b) {
return 180 - (a + b);
}
const otherAngle = (a, b) => 180 - a - b
Given a string of digits, you should replace any digit below 5 with '0' and any
digit 5 and above with '1'. Return the resulting string.
Note: input will never be an empty string
function fakeBin(x){
//숫자 문자열이 주어지면 5 이하의 숫자는 '0'으로, 5 이상의 숫자는 '1'로 바꿔야 합니다. 결과 문자열을 반환합니다.
//참고: 입력은 절대 빈 문자열이 될 수 없습니다.
const str = x.split("");
const result = str.map((i)=>{
return Number(i) >= 5 ? 1:0
});
return result.join("")
}
function fakeBin(x) {
return x.split('').map(n => n < 5 ? 0 : 1).join('');
}
function fakeBin(x) {
return x.replace(/\d/g, d => d < 5 ? 0 : 1);
}
Create a function that gives a personalized greeting. This function takes two parameters: name
and owner
.
Use conditionals to return the proper message:
case | return |
---|---|
name equals owner | 'Hello boss' |
otherwise | 'Hello guest' |
function greet (name, owner) {
return `Hello ${name === owner ? 'boss' : 'guest'}`
}
function greet (name, owner) {
return name === owner ? 'Hello boss' : 'Hello guest';
}
In this game, the hero moves from left to right. The player rolls the dice and moves the number of spaces indicated by the dice two times.
Create a function for the terminal game that takes the current
position of the hero and the roll (1-6) and return the new position.
move(3, 6) should equal 15
function move (position, roll) {
// return the new position
return position + (roll*2)
}
const move = (position, roll) => position + roll * 2
function move (position, roll) {
return position + roll * 2
}
This function should test if the factor
is a factor of base
.
Return true
if it is a factor or false
if it is not.
Factors are numbers you can multiply together to get another number.
2 and 3 are factors of 6 because: 2 * 3 = 6
%
) in most languages to check for a remainderFor example 2 is not a factor of 7 because: 7 % 2 = 1
Note: base
is a non-negative number, factor
is a positive number.
function checkForFactor (base, factor) {
return base % factor === 0 ? true : false
}
function checkForFactor (base, factor) {
return base % factor === 0;
}
const checkForFactor = (base, factor) => base % factor === 0;