Calculator Tools Calculator Tools
Create

Awesome Playlist Maker

Nov 13, 2023

About this app

Create and manage awesome playlists

Awesome Playlist Maker Create Awesome Playlist Add Song

Related apps

Put this on your site

Source

                    <html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">

<title>Awesome Playlist Maker</title>
<meta name="description" content="Create and manage awesome playlists">
<meta name="keywords" content="playlist, music, songs, create, manage">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

<script type="text/javascript">
try {
// App Javascript Goes Here. Place your entire script content inside the try block for error handling.
document.addEventListener("DOMContentLoaded", function() {
// Array to store playlist data
var playlist = [];

// Function to add a song to the playlist
function addSong() {
var songName = document.getElementById("songName").value;
var artistName = document.getElementById("artistName").value;

if (songName && artistName) {
playlist.push({ song: songName, artist: artistName });

// Clear the input fields
document.getElementById("songName").value = "";
document.getElementById("artistName").value = "";

// Render the updated playlist
renderPlaylist();
}
}

// Function to remove a song from the playlist
function removeSong(index) {
playlist.splice(index, 1);

// Render the updated playlist
renderPlaylist();
}

// Function to render the playlist
function renderPlaylist() {
var playlistContainer = document.getElementById("playlistContainer");
playlistContainer.innerHTML = "";

for (var i = 0; i < playlist.length; i++) {
var song = playlist[i].song;
var artist = playlist[i].artist;

var listItem = document.createElement("li");
listItem.className = "list-group-item";
listItem.innerHTML = `
<div class="d-flex justify-content-between align-items-center">
<div>
<h5>${song}</h5>
<p>${artist}</p>
</div>
<button class="btn btn-danger" onclick="removeSong(${i})">
<i class="fa fa-trash"></i> Remove
</button>
</div>
`;

playlistContainer.appendChild(listItem);
}
}

// Attach event listener to add button
var addButton = document.getElementById("addButton");
addButton.addEventListener("click", addSong);

// Render the initial playlist
renderPlaylist();
});

} catch (error) {
// This will throw the error to the parent window.
throw error;
}
</script>

<style>
/* App CSS Goes Here */
body {
background-color: #f8f9fa;
font-family: 'Roboto', sans-serif;
}

.container {
max-width: 600px;
margin: 0 auto;
padding-top: 40px;
}

h1 {
text-align: center;
margin-bottom: 30px;
}

.form-group {
margin-bottom: 20px;
}

.list-group-item {
background-color: #ffffff;
border: none;
border-radius: 8px;
margin-bottom: 10px;
}

.btn-danger {
background-color: #dc3545;
border: none;
border-radius: 8px;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<h1>Create Awesome Playlist</h1>

<div class="form-group">
<input type="text" class="form-control" id="songName" placeholder="Song Name">
</div>

<div class="form-group">
<input type="text" class="form-control" id="artistName" placeholder="Artist Name">
</div>

<button class="btn btn-primary" id="addButton">
<i class="fa fa-plus"></i> Add Song
</button>

<ul class="list-group" id="playlistContainer"></ul>
</div>
</body>
</html>