How to write an if/else statement with printing an image being an option?

So I’m trying to figure out how to use a window.prompt, and then if the user answers “yes”, to have an image printed on our page. Currently the script looks like this:

var answer
answer = window.prompt("Do you like google?");

 if(answer=="yes") {
 // print an image
 }
 else if(answer=="no") {
   window.alert("no")
 }
 else {
    window.alert("invalid")
 }

Is there a way to get it to print in the body of the page? Also as a side question, is there a way to make the answer non-case sensitive, or if I’m using if/else statements would I have to use a + operator to account for capitalization.

sure, look up DOM manipulation methods

I don’t think + does what you want

anyway, look up toLowerCase and toUpperCasemethods


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

2 Likes

Hey thanks! I was trying to figure out how to change the formatting but you answered so quickly, I appreciate it.

Also for toLowerCase,

  answer = window.prompt("Do you like google?");
    var lower = answer.toLowerCase();

Something like this worked for me! Thanks again, I’m off to research DOM manipulation methods.

what should I do?