Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • 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.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • 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:

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom