-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (23 loc) · 1.04 KB
/
script.js
File metadata and controls
32 lines (23 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// const button=getElementById("button")
// function Generate() {
// const stories = [
// "Once upon a time, a cat learned to code in JavaScript!",
// "In a small village, a robot baked the best cookies ever.",
// "A dragon decided to become a web developer instead of guarding treasure.",
// "The wizard’s spell accidentally created a website instead of a potion.",
// "One day, a student coded all night and their laptop turned into a spaceship!"
// ];
// const story= document.getElementById("story");
// const randomIndex= Math.floor(Math.random()* stories.length);
// story.textContent=stories[randomIndex]
// };
async function generateStory() {
const prompt = document.getElementById("storyInput").value;
const response = await fetch("https://story-generator-2wq4.vercel.app/api/generate-story", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ prompt })
});
const data = await response.json();
document.getElementById("storyOutput").textContent = data.story;
}