• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Expired post with callback

Danzen

New Coder
I have to expired people post with a callback function and onPostExpired(callback):
JavaScript:
<script type="text/javascript">
    (async function() {
        //opgave 1

        let flashChatter = await apiSimpleSignup();

        flashChatter.onPostReceived((post) => {
            let textbox = document.getElementById("tekstboks")
            let list = document.createElement("ul")
            textbox.appendChild(list)

            let tid = document.createElement("li")
            let tidText = document.createTextNode("timestamp:" + post.timestamp)
            tid.appendChild(tidText)

            let kanal = document.createElement("li")
            let channeltext = document.createTextNode("channel:" + post.channel)
            kanal.appendChild(channeltext)

            let userName = document.createElement("li")
            let usertext = document.createTextNode("username:" + post.username)
            userName.appendChild(usertext)

            let besked = document.createElement("li")
            let messagetext = document.createTextNode("message:" + post.message)
            besked.appendChild(messagetext)

            textbox.appendChild(tid)
            textbox.appendChild(kanal)
            textbox.appendChild(userName)
            textbox.appendChild(besked)

            textbox.classList.add('postid')

            console.log(post);
        });
        // opgave 2

        let fname = document.getElementById("fname")
        let button = document.getElementById("send")
        button.addEventListener("click", function (){
            let postObject =  {
                message: fname.value
            }
            flashChatter.post(postObject)
        });
// opgave 4



    })();
    //opgave 3
    (async function() {

        let flashChatter = await apiSimpleSignup();

        flashChatter.usernames((users) => {
            let liste = document.getElementById("brugere")
            for(user of users.data){
                let punkt = document.createElement("li")
                let punktTekst = document.createTextNode("Bruger:" + " " + user)
                punkt.appendChild(punktTekst)
                liste.appendChild(punkt)
            }

        })
        flashChatter.onUserConnected(fjern()){
          
        }

        function fjern () => {
           let fjern = document.getElementsByClassName('postid')
           fjern.remove();

        };


    })();
 
Last edited by a moderator:
Top