Skip to content

Instantly share code, notes, and snippets.

@trafficinc
Last active December 23, 2017 14:15
Show Gist options
  • Save trafficinc/1317f3a3e6cb35f6bf2fed2044f5a5e0 to your computer and use it in GitHub Desktop.
Save trafficinc/1317f3a3e6cb35f6bf2fed2044f5a5e0 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script>
var url = "http://www.mysite.com";
var link = "Go to MySite";
var html2 = sprintf( '<a href="%s">%s</a>', url, link );
var html3 = sprintf( '<a href="%s">%d</a>', url, 34 );
console.log(html2);
function sprintf( format )
{
for( var i=1; i < arguments.length; i++ ) {
if (Number.isInteger(arguments[i])) {
format = format.replace( /%d/, arguments[i] );
} else {
format = format.replace( /%s/, arguments[i] );
}
}
return format;
}
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment