Developing an innovative LeaderBoard featuring personalized profile images

I am looking for a way to implement a dynamic leaderboard using JavaScript, where the Users Points are stored in variables and their ranks change automatically based on point updates...

Here is the desired outcome:

https://i.sstatic.net/uyCa8.png

The idea is to manually input the User's Points Data using JavaScript Variables, with all data sourced from a JavaScript array.

For example:

   user_1 = Nilesh S;
   user_2 = Shristi_S; 

   user_1 points = 1710;
   user_2 points = 1710;

   etc...

If I were to update Nilesh S (user_1) points to 1000, then Nilesh S rank would adjust accordingly to 10th...

Currently, I have managed to display circular profile pictures only :)

Below are the snippets of code:

Javascript:

var img = document.createElement("IMG");
  img.setAttribute("src", "img_pulpit.jpg");
  img.setAttribute("width", "300");
  img.setAttribute("height", "300");
  img.setAttribute("alt", "The Pulpit Rock");
  document.body.appendChild(img);

HTML:

<div id="IMG">
<script src="Script.js"></script>
<link rel="stylesheet" type="text/css" href="Style.css">
  [1]: https://i.sstatic.net/zXm4N.png

CSS:

img {
      background: #2f293d;

   border: 1px solid #2f293d;
   padding: 6px;
   border-radius: 50%;
   box-shadow: .6rem .5rem 1rem rgba(0, 0, 0, .5);

}

Any help or solution provided will be highly appreciated.

Answer №1

Check out this simple method to generate placeholder data in an array of objects, arrange it in order, and display it on a webpage.

// Define an array to store profile objects
let profiles = [];

// Create the first profile
let profile1 = {};
profile1.name = "John Doe";
profile1.points = 1200;
profiles.push(profile1);

// Second profile
let profile2 = {};
profile2.name = "Alice Johnson";
profile2.points = 1450;
profiles.push(profile2);

// Third profile
let profile3 = {};
profile3.name = "Chris Brown";
profile3.points = 900;
profiles.push(profile3);

// Fourth profile
let profile4 = {};
profile4.name = "Emily White";
profile4.points = 1700;
profiles.push(profile4);

// Sort profiles by points (highest first)
profiles.sort(function(a, b) { 
return b.points - a.points;
})

// Targeting the element with 'profiles' class
let profilesDiv = document.getElementsByClassName('profiles')[0];

// Display each profile on the page
profiles.forEach(function(entry) {
let profile = document.createElement('div');
    profile.className = "profile";
    profile.textContent = entry.name + " -- " + entry.points;
profilesDiv.appendChild(profile);
});
.profile {
  border: 2px solid #222222;
  padding: 5px;
  margin: 5px;
  width: 50%;
}
<div class="profiles">

</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is causing the large build size when using Webpack with Vue.js?

After cloning the repository at: https://github.com/Microsoft/TypeScript-Vue-Starter I executed npm scripts: npm install npm run build The outcome: the size of build.js file is approximately 1MB. Can anyone explain why the build.js file is significant ...

extracting generated hyperlinks through a JavaScript function via webdriver

Looking for help with accessing a tricky href that cannot be hardcoded due to dynamic generation: Base classes https://gist.github.com/codyc4321/724f05aca8f6775e2fc1 (access_link of interest) class HCCDriver(FirefoxDriver): def __init__(self, userna ...

Launching a personalized Mailchimp form

I am trying to implement a custom mail chimp form that pops up upon page load, similar to what Groupon and Fab do. I have the code for the form copied on our server but I'm struggling to create a pop-up effect when the page loads. I have tested shadow ...

What is causing my mobile version not to resize and adjust to fit the screen properly?

Currently utilizing Bootstrap 4 along with the viewport meta tag, %meta{:content => "width=device-width, initial-scale=1, shrink-to-fit=no", :name => "viewport"}/ Even after hiding all images with .hidden-xs-up, the display on Chrome mobile appear ...

Mobile application showing alerts for connected devices

In the process of creating a hybrid mobile app, I'm looking to incorporate notifications in the top right corner of the application. The frontend consists of html and angularjs, while the backend utilizes spring rest web service. To convert the front ...

Establishing a class for wp_nav_menu

Is there a way to transform the following code: <ul class="ulStyle"> <li class="liStyle"> <div class="first"> <div class="second"> menu1 </div> </div> </li> </ul> into wp_nav_menu? I'm struggling with ...

Zebra Calendar Alignment Problem

Currently working on an asp.net app and utilizing the Jquery Zebra DatePicker. Encountering an issue where when opening the form in a Jquery dialog, the calendar appears at the bottom of the page instead of within the dialog. A similar problem was discus ...

Accessing component variables within an event in Angular 2 (dealing with scope problems)

I am currently facing an issue with scoping in my component click event. Specifically, I need to access private variables within the component, but the keyword this now refers to the event scope rather than the component's. This has led to an error wh ...

Adjusting BackstopJS - Each scenario file is interpreted as an individual scenario rather than a group of scenarios in the configuration file

As I strive to scale BackstopJS by breaking down the original backstop.json file into a directory of structured scenario JSON files, I'm encountering an issue where the function in my config file interprets each JSON file as a single scenario instead ...

Adjusting layout once image has been removed from view

I am working on a code where I want to hide an image on small screens and center the input fields when the screen size is XS. I have tried adjusting the Bootstrap 4 flex settings without success. Is there a way to achieve this using Bootstrap or SASS? & ...

In my coding project using Angular and Typescript, I am currently faced with the task of searching for a particular value within

I am facing an issue where I need to locate a value within an array of arrays, but the .find method is returning undefined. import { Component, OnInit } from '@angular/core'; import * as XLSX from 'xlsx'; import { ExcelSheetsService } f ...

What is the best method for sending JSON data to an ASP Server through AJAX?

I'm currently working on a website built with ASP.NET that requires data retrieval from CloudKit. Utilizing CloudKit JS, I successfully retrieve a record from CloudKit and aim to send the data to the server using C# in my JavaScript code. I can conver ...

Adding a regional iteration of a library that was unable to be loaded

Recently, I have been experimenting with PhantomJS to capture screenshots of a webpage every five minutes. While the process runs smoothly most of the time, I encountered an issue where the AngularJS library fails to load intermittently. This results in th ...

Angular's innerHTML dilemma

Within my Angular service, I have implemented three methods as shown below: public loadLiveChat() { let url: string; url = this.appConfig.config.liveAgent.liveAgentScriptUrl; this.dynamicallyLoadScript(url); ...

Deleting a node within a react-sortable-tree

As I delve into the world of React, I am eager to incorporate a react-tree component into my project. One hurdle I am facing is figuring out how to remove a node within the function removeNode(): removeNode(e){ this.setState({ treeData: rem ...

Retrieve Images from URL - Similar to Facebook Thumbnails

I am in the process of creating a website similar to "Reddit." Users will have the option to share URLs, and I would like to use PHP to extract the correct image from these links. What I'm looking for is a more advanced script that can retrieve imag ...

Reverse the orientation of the SVG image, for instance, the graph

I've been experimenting with creating a bar graph using SVG, but I'm struggling to understand how it works. I tried rotating an existing graph upside down, but there seems to be a small offset. You can view the corresponding jsfiddle here - http: ...

Utilizing an event emitter to read from a text file

I have a text file with multiple lines containing data such as pepperoni pizza, pizza margherita, etc. I am trying to create an EventEmitter that will trigger specific events based on the content of the file. For example, if the word "pepperoni" is found ...

When refreshing, the useEffect async function will not execute

Upon page load, the getImages function is intended to run only once. After refreshing the page, both tempQuestionImages and questionImages are empty. However, everything works perfectly after a hot reload. I am utilizing nextJs along with Firebase Cloud ...

The Vue router-view is not showing certain views as expected

Apologies for the extensive text. All of my router-views are functioning properly, except for one specific view which appears blank. Despite meticulously reviewing the code multiple times, I cannot identify any errors or warnings in the console. The struct ...