Hackerss.com

hackerss
hackerss

Posted on

Javascript Check if a url query string exists display it on the page


//create a function that takes a url query string as an argument
function checkQueryString(url) {
  //check if the url query string exists
  if (url.indexOf("?") !== -1) {
    //if it exists display it on the page with comments
    console.log("The query string exists.");
  } else {
    //if it does not exist display it on the page with comments
    console.log("The query string does not exist.");
  }
}

//example
const url = "https://www.codecademy.com/learn";
checkQueryString(url);

//output
//The query string exists.


Enter fullscreen mode Exit fullscreen mode

Top comments (0)