Skip to content

Commit 57bd5eb

Browse files
Add: CodeSandboxes 112. & 113.
1 parent 7969fba commit 57bd5eb

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3998,7 +3998,7 @@ alert("Username: " + username);
39983998

39993999
- The code above demonstrates how to use `localStorage` to store and retrieve data.
40004000
- The `setItem()` method is used to store a key-value pair ("username" and "John") in local storage.
4001-
- Later, the `getItem()` method retrieves the value associated with the "username" key, which is then logged to the console.
4001+
- Later, the `getItem()` method retrieves the value associated with the "username" key, which is then alerted to the user.
40024002

40034003
#### Canvas API
40044004

@@ -4081,24 +4081,30 @@ The WebSocket API enables full-duplex communication between web browsers and ser
40814081

40824082
```javascript
40834083
// Create a WebSocket connection
4084-
var socket = new WebSocket("ws://localhost:8080");
4084+
const socket = new WebSocket("wss://echo.websocket.org");
40854085

40864086
// Handle connection open event
40874087
socket.onopen = function(event) {
4088-
console.log("WebSocket connected!");
4088+
alert("WebSocket connected!");
40894089
};
40904090

40914091
// Handle message received from server
40924092
socket.onmessage = function(event) {
4093-
console.log("Message received: " + event.data);
4093+
alert("Message received: " + event.data);
40944094
};
40954095

40964096
// Send a message to the server
40974097
socket.send("Hello from client!");
40984098
```
40994099

4100+
[![Edit 112-WebSocket API](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/sandbox/112-websocket-api-dypkvz)
4101+
4102+
- [^112]CodeSandbox: WebSocket API.
4103+
4104+
[^112]:[CodeSandbox: WebSocket API.](https://dypkvz.csb.app/), last access: October 2, 2024.
4105+
41004106
- The code above demonstrates how to establish a WebSocket connection with a server.
4101-
- Upon successful connection (`onopen` event), the client logs a message to the console.
4107+
- Upon successful connection (`onopen` event), the client logs a message to the alert popup.
41024108
- Messages received from the server are handled via the `onmessage` event handler.
41034109
- Messages can be sent to the server using the `send()` method.
41044110

@@ -4122,12 +4128,18 @@ document.getElementById("dropzone").addEventListener("dragover", function(event)
41224128
});
41234129
document.getElementById("dropzone").addEventListener("drop", function(event) {
41244130
event.preventDefault();
4125-
var data = event.dataTransfer.getData("text/plain");
4131+
const data = event.dataTransfer.getData("text/plain");
41264132
event.target.textContent = "Dropped: " + data;
41274133
});
41284134
</script>
41294135
```
41304136

4137+
[![Edit 113-Drag and Drop API](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/sandbox/113-drag-and-drop-api-fsswsl)
4138+
4139+
- [^113]CodeSandbox: Drag and Drop API.
4140+
4141+
[^113]:[CodeSandbox: Drag and Drop API.](https://fsswsl.csb.app/), last access: October 2, 2024.
4142+
41314143
- The code above demonstrates how to implement drag-and-drop functionality using the Drag and Drop API.
41324144
- The `draggable` attribute is set to `true` on the draggable element, indicating that it can be dragged.
41334145
- Event listeners are added to handle the `dragstart` event for initiating the drag operation, and the `dragover` and `drop` events for defining drop targets and handling dropped elements.

0 commit comments

Comments
 (0)