Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rick Rubin Synth</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
    <div id="keyboard">
    <div class="key yellow" id="key1"></div>
    <div class="key green" id="key2"></div>
    <div class="key blue" id="key3"></div>
    <div class="key orange" id="key4"></div>
    <div class="key brown" id="key5"></div>
    <!-- Add more keys as needed -->
</div>
<script src="script.js"></script>
</body>
</html>
              
            
!

CSS

              
                body {
    display: flex;
    justify-content: center; /* Center horizontally */
    align-items: center; /* Center vertically */
    height: 100vh; /* Full viewport height */
    margin: 0; /* Remove default margin */
    background-color: #f0f0f0;
}

#keyboard {
    display: flex;
    flex-wrap: wrap; /* Allow the keys to wrap onto the next line */
    justify-content: center; /* Center keys horizontally */
    align-items: center; /* Center keys vertically */
}

.key {
    width: 60px;
    height: 60px;
    margin: 5px;
    background-color: #333;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    color: white;
    cursor: pointer;
    border: 3px solid #666;
    box-shadow: 3px 3px 0 #000;
}

.key:active {
    transform: translate(3px, 3px);
    box-shadow: none;
}

/* Color-specific key styles */
.yellow { background-color: #f2cc8f; }
.green { background-color: #2ecc71; }
.blue { background-color: #3498db; }
.orange { background-color: #eb5e28; }
.brown { background-color: #403d39; }

              
            
!

JS

              
                document.addEventListener('DOMContentLoaded', () => {
    console.log("DOM fully loaded and parsed");
    const keys = document.querySelectorAll('.key');
    console.log("Keys found:", keys.length); // Log the number of keys found
    keys.forEach(key => {
        key.addEventListener('click', () => {
            console.log(`Key clicked: ${key.id}`); // Log which key is clicked
            playSound(key.id);
        });
    });
});

function playSound(keyId) {
    console.log(`Playing sound for: ${keyId}`); // Log which key's sound is being played
    let audio;
    switch (keyId) {
        case 'key1':
            console.log("Sound 1 is being loaded");
            audio = new Audio('https://www.dropbox.com/scl/fi/t48fhwc6dvmuf5163wjok/its-fascinating-3.mp3?rlkey=yktbbng40dtj1y2v34qn4um08&dl=1');
            break;
        case 'key2':
            console.log("Sound 2 is being loaded");
            audio = new Audio('https://www.dropbox.com/scl/fi/ona6t75hdom6jgoz51qjq/amazing-3.mp3?rlkey=lt33ep22g2m4x66x5fh2bnlnf&dl=1');
            break;
        case 'key3':
            console.log("Sound 3 is being loaded");
            audio = new Audio('https://www.dropbox.com/scl/fi/0aocz2o1ghnfls8zcmamt/lucky-pants.mp3?rlkey=7sexgdt9ntznzlnuqp97b8u6s&dl=1');
            break;
        case 'key4':
            console.log("Sound 4 is being loaded");
            audio = new Audio('https://www.dropbox.com/scl/fi/136oq7vpae7m5r61q2a5a/that-s-a-good-idea-3.mp3?rlkey=bpqx16p9lxu7i624mfjfnd1ax&dl=1');
            break;
        case 'key5':
            console.log("Sound 5 is being loaded");
            audio = new Audio('https://www.dropbox.com/scl/fi/8rcspb07tye0gezpn7dzi/nobody-knows-2.mp3?rlkey=ni1zb3sl4pblfogd5hdnpdkz1&dl=1');
            break;
        // Add more cases as per your key ids
    }
 // Load the audio metadata
    audio.load();

    // Attempt to play the audio
    audio.play().then(() => {
        console.log("Playback successful.");
    }).catch(err => {
        console.log("Playback failed.", err);
        // Handle the failure gracefully
        // You might want to display an error message to the user
    });
}

              
            
!
999px

Console