0

I just started to learn Javascript and basically I wanted to create a bookmark on Google Chrome where I basically just want to do:

"www.hello" + i + ".com"

so basically open up a prompt where I myself enter what I want "i" to be and then it should then add up so etc:

i = world

end: www.helloworld.com (Automatic open it up).

I assume this is beginner level but I have just learned and I just know how to open up a prompt at this moment.

javascript:(()=>{let i=prompt("Enter "i" for website ,")

and now I dont know how to continue to make it add for a website.

Andres123
  • 7
  • 1
  • 7

2 Answers2

4

That's very simple..

Just copy paste the code below and save it in your bookmark and give it a try..

javascript:var websiteName = prompt("Enter \"i\" for website..");var url = "http://www.hello"+websiteName+".com";window.location.href = url;

Note that javascript: at the front will be automatically removed when you copy and paste the code manually in url bar. So save it once in bookmark and use.

Ganesh
  • 1,820
  • 2
  • 20
  • 40
0

You can pretty much use whatever you would normally put between <script> tags on your page. So this:

var i = prompt("Enter website:", "");
if (i == null || i == "") {
    //add whatever action you would like when user cancels
} else {
    window.open("https://www."+ i +".com");
}

Becomes this (minus the comments):

javascript: var i = prompt("Enter website:", ""); if (i == null || i == "") { } else { window.open("https://www."+ i +".com"); }