Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

object #21

Open
wants to merge 1 commit into
base: challenge
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion basic/script.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
// ループ・配列・データ型の問題
export const func1 = (n) => {
// このコードを完成させてください
if (n < 0) {
return [];
}
const list = [];
for (let i = 1; i <= n; i++) {
list.push(i);
}
return list;
};

// 条件分岐・データ型の問題
export const func2 = (n) => {
// このコードを完成させてください
// 正の整数でない場合は 'error' を返す
if (typeof n !== "number" || n <= 0 || !Number.isInteger(n)) {
return "error";
}

// 15の倍数の場合(3と5の両方の倍数)
if (n % 15 === 0) {
return "FizzBuzz";
}
// 3の倍数の場合
else if (n % 3 === 0) {
return "Fizz";
}
// 5の倍数の場合
else if (n % 5 === 0) {
return "Buzz";
}
// それ以外の場合、数値を文字列にして返す
else {
return n.toString();
}
};
10 changes: 10 additions & 0 deletions object/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ const person = {

export const func1 = () => {
// このコードを完成させてください
let newperson = { ...person };
newperson.gender = "male";
newperson.interests = [
{ name: "programming", emoji: "💻" },
{ name: "motorcycle", emoji: "🏍" },
];
return newperson;
};

export const func2 = () => {
// このコードを完成させてください
return JSON.stringify(person);
};

const jsonStr = `
Expand Down Expand Up @@ -40,4 +48,6 @@ const jsonStr = `

export const func3 = () => {
// このコードを完成させてください
let userdata = JSON.parse(jsonStr);
return userdata.name + "," + userdata.email + "," + userdata.company.name;
};