Sugarcube 2 how to make random images help

How to show random photos or videos every time we enter different in one passage ?
I wrote this code in the passage, but the photos does not appear

<img id="random-image" src="">
$(document).on(':passagerender', function() {
    // Fotoğraf URL'lerini buraya ekleyin
    var photoURLs = [
        // ... diğer fotoğraf URL'leri

    // Rastgele bir fotoğraf seçme işlemi
    var randomIndex = Math.floor(Math.random() * photoURLs.length);
    var randomPhotoURL = photoURLs[randomIndex];

    // Rastgele seçilen fotoğrafın gösterilmesi
    $('#random-image').attr('src', randomPhotoURL);

Hi there!

Unfortunately we can’t see your code well. Could you use the Pre-formatted text (the </> icon) for the whole bit of code?

hi sir every time helping me thanks. I can do maximum this

The problem is that it’s still eating text (and important bit of code). What you want is to do something like this :


so it looks like :


one minute please



Are you using a nobr tag on the passage? or the Config.passage.nobr in your JavaScript?
(because \\ Comments can break inside of the <<script>> macro)

Otherwise you could use basic Sugarcube:

<<set _image to either("URL1", "URL2", "URL3")>>
<img @src="_image">

The either() function, and the @ Atribute directive

1 Like

No, I started a new story and tried it, that is, I only wrote this code and nothing else. Now I will try the code you gave. Thanks

it worked thank you very much