ChatGptでプログラミングをさせることはできるのか。
また、初心者でも何か簡単な成果物を作成できるのか試してみました。
今回は、簡単なメモ帳アプリを作成します。
言語はHTML,CSS,Javascriptを使用します。
ChatGptへの質問の仕方
ChatGptには、なるべく具体的に質問や要求をした方が良い結果が返ってきやすいです。
今回私は、下記のような質問をしました。
ChatGptへの質問内容
プログラミングでメモ帳アプリを作成してください。
①言語はHTML,CSS,Javascriptで作成してください。
②おしゃれで見やすいデザインにしてください。
③メモの入力と表示の機能をいれてください。
④メモの保存機能をいれてください。
⑤メモのクリア機能をいれてください。
⑥メモには見出しと本文を記入し、保存したメモからは見出しが見えるようにしてください。
⑦保存したメモの見出しをクリックすると、メモ本文を表示非表示の切り替えができるようにしてください。
④~⑦については要望しなかった場合、機能が組み込まれませんでした。
その場合は上記のように必要な機能を、細かに記載すると良いと思います。
ChatGPTが作成したメモ帳アプリ
初期画面
メモを追加した画面
スーパー買い物のメモ本文を表示させた画面
ソースコード
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>メモ帳アプリ</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>メモ帳</h1>
<div class="input-container">
<input type="text" id="title" placeholder="見出しを入力">
<textarea id="memo" placeholder="ここにメモを入力してください"></textarea>
</div>
<div class="memo-display" id="memoDisplay"></div>
<button onclick="saveMemo()">保存</button>
<button onclick="clearMemo()">クリア</button>
<div class="memo-list" id="memoList"></div>
</div>
<script src="script.js"></script>
</body>
</html>
style.css
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
}
.container {
max-width: 600px;
margin: auto;
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
font-size: 24px;
margin-bottom: 20px;
}
.input-container {
display: flex;
flex-direction: column;
margin-bottom: 20px;
}
input[type="text"], textarea {
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 10px;
width: 100%;
box-sizing: border-box;
}
button {
padding: 10px 20px;
font-size: 14px;
margin-right: 10px;
cursor: pointer;
}
button:last-child {
margin-right: 0;
}
.memo-list div {
padding: 10px;
cursor: pointer;
border-radius: 5px;
margin-bottom: 5px;
background-color: #f0f0f0;
}
.memo-list div:hover {
background-color: #e0e0e0;
}
script.js
const titleInput = document.getElementById('title');
const memoInput = document.getElementById('memo');
const memoList = document.getElementById('memoList');
function saveMemo() {
const title = titleInput.value.trim();
const memo = memoInput.value.trim();
if (title === '' || memo === '') {
alert('見出しとメモの内容を入力してください。');
return;
}
const memoItem = document.createElement('div');
memoItem.textContent = title;
memoItem.addEventListener('click', () => toggleMemoDisplay(memo));
memoList.appendChild(memoItem);
titleInput.value = '';
memoInput.value = '';
}
function toggleMemoDisplay(memo) {
const memoDisplay = document.getElementById('memoDisplay');
if (memoDisplay.textContent === memo) {
memoDisplay.textContent = '';
} else {
memoDisplay.textContent = memo;
}
}
function clearMemo() {
memoList.innerHTML = '';
}
ChatGptでプログラミングをさせるメリット
・初心者でもプログラミングできる。・経験者でも作業効率化できる
・簡単なフォーマットができる
初心者でもプログラミングできる
要件が複雑になれば、稀にバグのあるコーディングをしてしまう場合があります。
経験者でも作業効率化できる
ケースバイケースだとは思いますが、仕様がシンプルで開発スピードを上げたい場合は便利です。
簡単なコーディングはChatGptにお願いをし、その間に別の作業をすることができるでしょう。
簡単なフォーマットができる
ChatGptに簡単なフォーマットを作成してもらい、その後に自分でアレンジしてコーディングをする使用方法も便利だと思います。
コメント