This repository was archived by the owner on Jan 3, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathexercise-1.js
More file actions
46 lines (34 loc) · 1.43 KB
/
exercise-1.js
File metadata and controls
46 lines (34 loc) · 1.43 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Let's build a webchat to communicate with each other!
The requirements of a basic webchat are:
- The user can write a message in an input and send it after clicking on the submit button.
- After clicking on the submit button, the input should be empty.
- The user can read the existing messages in the message list.
- The message list is refreshed automatically every few seconds so
the user can keep reading the incoming messages without refreshing the page.
========
Task 1
========
Your task is to build the webchat frontend.
Some code is already written in index.html, that you can open in your browser.
For the purpose of this exercise, you are provided a server which you can interact
with to get and save messages. Some messages already exist on the server.
Your first task is to display those messages in the page,
in the HTML element with the id "message-list". Use the following API to get the messages:
HTTP Verb: GET
API: https://codeyourfuture.herokuapp.com/api/messages
===============
Expected result
===============
When you open index.html in your browser, it should display the existing messages on the page.
*/
// Write your code here
let url = `https://codeyourfuture.herokuapp.com/api/messages`;
fetch(url).then(function(response) {
return response.text();
}).then(function(message){
let myMessage = document.getElementById("message-list");
console.log(message);
myMessage.innerText = message;
return;
})