Introduction
In this lab, we will dive into the world of JavaScript programming and explore various concepts such as variables, data types, conditional statements, loops, and functions. Through a series of hands-on exercises and coding challenges, you will learn how to write clean and efficient JavaScript code, and gain a solid understanding of the fundamental principles that underpin this powerful programming language. By the end of this lab, you will be equipped with the skills and knowledge needed to tackle more complex JavaScript projects with confidence.
Function to Check if a String is an Absolute URL
To check if a given string is an absolute URL, follow these steps:
- Open the Terminal/SSH and type
nodeto start practicing coding. - Use
RegExp.prototype.test()to test if the string is an absolute URL. - The function should be defined as
const isAbsoluteURL = str => /^[a-z][a-z0-9+.-]*:/.test(str); - The function takes a string argument
strand returnstrueif the string is an absolute URL, andfalseotherwise. - Test the function using the examples provided:
isAbsoluteURL("https://google.com"); // true
isAbsoluteURL("ftp://www.myserver.net"); // true
isAbsoluteURL("/foo/bar"); // false
Summary
Congratulations! You have completed the Check if Absolute URL lab. You can practice more labs in LabEx to improve your skills.