Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
HTML
<!DOCTYPE html>

  <div class="row flex-center">
    <div class="col-8 col">
      <h2>AAA URL Shortener</h2>
      
        <div class="form-group">
          URL Here:
          
            <script>
            function generatePath id="url" (path = 'url') {
            let characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
            let position = Math.floor(Math.random() * characters.length)
            let character = characters.charAt(position)
            if (path.length === 7) {
            return path
             }
            return generatePath(path + character)
            </script>
        </div>
        <div id="message" class="alert alert-primary"></div>
        
      
      <p class="padding-top">
      </p>
    </div>
  </div>

<script>
   function generatePath id="url" (path = 'url') {
    let characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
    let position = Math.floor(Math.random() * characters.length)
    let character = characters.charAt(position)
  if (path.length === 7) {
    return path
  }
  return generatePath(path + character)
  </script>
  <div id="clockbox" style="font: 14pt Arial; color: #CCCCFF">
    <script>
      tday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
      tmonth=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
      
      function GetClock(){
      var d=new Date();
      var nday=d.getDay(),nmonth=d.getMonth(),ndate=d.getDate(),nyear=d.getFullYear();
      var nhour=d.getHours(),nmin=d.getMinutes(),nsec=d.getSeconds(),ap;
      
      if(nhour==0){ap=" AM";nhour=12;}
      else if(nhour&lt;12){ap=" AM";}
      else if(nhour==12){ap=" PM";}
      else if(nhour>12){ap=" PM";nhour-=12;}
      
      if(nmin&lt;=9) nmin="0"+nmin;
      if(nsec&lt;=9) nsec="0"+nsec;
      
      document.getElementById('clockbox').innerHTML=""+tday[nday]+", "+tmonth[nmonth]+" "+ndate+", "+nyear+" "+nhour+":"+nmin+":"+nsec+ap+"";
      }
      
      window.onload=function(){
      GetClock();
      setInterval(GetClock,1000);
      }
      </script>
      <div id="clockbox"></div>
    </div>



I cannot see the results of the shortening, and the function does not seem to be formatted properly. I would like the new URL to display on the same page.

What I have tried:

Various forms of script, both on page and in external document.
Posted
Updated 13-Jun-18 15:22pm
v2
Comments
Richard Deeming 14-Jun-18 12:11pm    
You can start by fixing the syntax errors in your generatePath function:
function generatePath(id="url", path = 'url') {
    const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    let position = Math.floor(Math.random() * characters.length);
    let character = characters.charAt(position);
    if (path.length === 7) {
        return path;
    }
    
    return generatePath(path + character);
}


Beyond that, your question is almost impossible to answer. You haven't provided any way for the user to enter a value or invoke your shortener. You haven't provided anywhere in the document to display the result. And you haven't shown how you're intending to map the randomly-generated string to the original URL.
Henry Mosley 17-Jan-22 2:55am    
I think this is the answer
Member 15713771 17-Aug-22 10:09am    
Thank you Richard

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900