-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
64 lines (55 loc) · 2.34 KB
/
script.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const chatLog = document.getElementById("chatLog");
const userInput = document.getElementById("userInput");
const sendButton = document.getElementById("sendButton");
const questions = [
"Do you often feel a sense of hopelessness or worthlessness?",
"Do you experience frequent changes in your appetite or weight?",
"Do you struggle with constant fatigue or lack of energy?",
"Do you have difficulty concentrating or making decisions?",
"Do you frequently experience feelings of sadness or tearfulness?",
"Do you find it challenging to enjoy activities or hobbies that used to bring you pleasure?",
"Do you often feel anxious, restless, or on edge?",
"Do you have trouble falling asleep, staying asleep, or experiencing restful sleep?",
"Do you have recurrent thoughts of death or suicidal ideation?",
"Do you feel a sense of isolation or disconnection from others?"
];
let currentQuestion = 0;
let noCount = 0;
function generateChatBubble(text, isUser) {
const chatBubble = document.createElement("div");
chatBubble.classList.add("chat-bubble");
chatBubble.classList.add(isUser ? "user" : "bot");
chatBubble.innerText = text;
chatLog.appendChild(chatBubble);
chatLog.scrollTop = chatLog.scrollHeight;
}
function askQuestion() {
generateChatBubble(questions[currentQuestion], false);
currentQuestion++;
}
function processUserInput() {
const answer = userInput.value;
generateChatBubble(answer, true);
if (answer.toLowerCase() === "yes") {
noCount++;
}
if (currentQuestion < questions.length) {
askQuestion();
} else {
if (noCount > 5) {
alert("It is recommended that you consult a therapist.");
} else {
generateChatBubble("Thank you for sharing. It appears that you are mentally fine! Remember to cherish each moment, find joy in the little things, and nurture your mental well-being. You deserve to lead a fulfilling and happy life. Stay positive and embrace the beauty that surrounds you. Wishing you continued happiness and contentment on your journey!", false);
}
userInput.disabled = true;cknjn jcn hc nvyfvjnnvujn ihrgn oiihg fjhrnr jhiirbbhiioji``
sendButton.disabled = true;
}
userInput.value = "";
}
askQuestion();
sendButton.addEventListener("click", processUserInput);
userInput.addEventListener("keyup", function(event) {
if (event.key === "Enter") {
processUserInput();
}
});