- 2

How to make and style bot response when creating a chat bot?

I have been trying to build a chat bot, but the users message I could display that by creating new html element in JavaScript, but the bots response was unable to display, please how do I make both text display and style them each differently thanks in advance....

20th Jun 2021, 7:00 PM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
23 odpowiedzi
+ 4
can you show an example code of what you mean ? I can't really understand what you are looking for , that's why asking for code . Or you can wait for others to help you out.
20th Jun 2021, 8:08 PM
Abhay
Abhay - avatar
+ 2
assuming you have a container target to display both user messages and bot response: when user enter a message, create an element to receive its text, assign it and a class name used to style user message, then append it to the container: user_msg = document.createElement("div"); user_msg.textContent = user_input_string; user_msg.classList.add("user-msg"); container.appendChild(user_msg); when bot answer some text, follow same path, but add a class used to style bot answers: bot_msg = document.createElement("div"); bot_msg.textContent = bot_string; bot_msg.classList.add("bot-msg"); container.appendChild(bot_msg);
20th Jun 2021, 9:04 PM
visph
visph - avatar
+ 2
Thanks lemme try it right away
22nd Jun 2021, 10:03 AM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
+ 2
It has worked thanks bro
22nd Jun 2021, 11:11 AM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
+ 1
Ikuobase Wisdom Ewaensetin little correction for the bot response to be correctly handled: if(x.match('hey')){ var b = document.createElement("h"); b.textContent="me"; list.appendChild(b); } however, you doesn't define the 'love' function called in body tag onload atteibute ;)
22nd Jun 2021, 10:14 AM
visph
visph - avatar
22nd Jun 2021, 10:08 AM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
0
Thanks lemme make corrections
22nd Jun 2021, 10:16 AM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
0
Please review
22nd Jun 2021, 10:25 AM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
22nd Jun 2021, 10:26 AM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
0
variable names used in my first post was only meaningful variable names examples ^^ you should adapt what I show as code to your own code ;P now, I only have the part of your original code I've corrected in my last post... as you have edited it :(
22nd Jun 2021, 10:29 AM
visph
visph - avatar
0
Please can you make corrections to my codes and save so I can view?
22nd Jun 2021, 10:31 AM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
0
from your original code, you would just had to style the 'h' element (wich is not a valid html5 element) to get the bot answer with its own style... even without styling it, the bot output displays differently from the user messages with my last code correction suggestion ^^
22nd Jun 2021, 10:32 AM
visph
visph - avatar
0
now, that's not corrections that you code require, but complete rewrite ^^
22nd Jun 2021, 10:35 AM
visph
visph - avatar
0
😮😪😥
22nd Jun 2021, 10:36 AM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
0
The HTML document is okay right?
22nd Jun 2021, 10:37 AM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
0
yes, it seems almost okay (doesn't have looked at it in detail, but it was working)
22nd Jun 2021, 10:38 AM
visph
visph - avatar
0
What about the CSS sir, any errors
22nd Jun 2021, 10:39 AM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
0
css also seems ok, even if could be improved (user message input lacks at least some left padding)... all others improvments are almost taste questions ;)
22nd Jun 2021, 10:42 AM
visph
visph - avatar
0
So the was in the js
22nd Jun 2021, 10:43 AM
Ikuobase Wisdom Ewaensetin
Ikuobase Wisdom Ewaensetin - avatar
0
???
22nd Jun 2021, 10:44 AM
visph
visph - avatar