I am developing a web "app" with JavaScript and jQuery with the help of a couple of other libraries for ease of use.

Its purpose is to collect user ID's and to build a list of "attackable" targets for the game at https://torn.com

Details for the API can be found at https://api.torn.com, although I'm pretty sure it requires an account to do anything with it (needs an API Key, and I don't want to provide mine for security purposes)

The entirety of the site is on my gitlab instance

My biggest concern is whether or not I have created effective and efficient code to accomplish the purpose of the app. Specifically, the API call and data handling is what I am most concerned with here.

    $.get( url, function( data ) {
        var username = data.name;
        var userlevel = data.level;
        var userstatus = data.status.description;
        var liuser = $('<li/>')
        var liname = $('<li/>')
        var listatus = $('<li/>')
        var liattack = $('<li/>')
        .html(`<a href="https://www.torn.com/loader.php?sid=attack&user2ID=${value}" class="button" target="_blank">Attack!</a>`)
        var liremove = $('<li/>')
        .html(`<a href="javascript:removeUser(${value})" type="button" class="button" id='removeuser${id}'>x</a>`)

This feels like a lot of work to do within a single API call. It works, and can be demo'd on the site it currently lives on: https://murdr.us

I'm also looking for a better input validation that can check for empty state or non-numbers entered and return an on-screen alert (rather than a browser alert as it currently shows).

here's the current validation method used:

function empty() {
    var x = $('input#useridValue').val();
    if (x == "") {
        alert("Enter a Valid User ID");
        return false;

and the button that calls it:

$("button#submitUser").click(function() {
    if (empty() !== false ) { 
    var tempid = parseInt($('input#useridValue').val());

I greatly appreciate your time, folks. Hopefully, some insight and optimization techniques may be devised from this.

Thanks, all.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.