简体   繁体   中英

questions with a pig latin translator

The code is here on jsFiddle :

Pig Latin Translator

<br>
<p style="font-family: verdana; text-align: center;">Enter one word and the program will translate it in to pig latin!</p>
<div style="text-align: center;">
    <input class="theinput" id="english" value="Word" title="Enter a single english word"></input>
    <br>
    <br>
    <button onclick="translate()" type="button">Translate</button>
    <br>
    <p id="output" style="size: 5; text-align: center; color: red; font-family: monospace;">ordway</p>
</div>
<script>
    function translate() {
        var english = document.getElementById("english").value;
        if ((english.charAt(0) == 'a') || (english.charAt(0) == 'e') || (english.charAt(0) == 'i') || (english.charAt(0) == 'o') || (english.charAt(0) == 'u')) {
            var pigLatin = english + "ay";
            document.getElementById("output").innerHTML = pigLatin;
        } else {
            alert("in progress');
        }
    }
</script>

However it does not set the paragraph to the translated pig latin word when I press the button. what can I do to fix ths?

If you look at the console log, you will see

SyntaxError: unterminated string literal
http://fiddle.jshell.net/_display/
Line: 54, Column: 22
Source code:
alert("in progress');

or something similar (depending on browser).

So there is a simple syntax error. Use

alert("in progress");

or

alert('in progress');

UPDATE: In chrome "Translate" is a reserved word and the function call to translate() won't work. In IE it will work correctly. Here's a fiddle which works in either browser.. jsfiddle.net/cCdC5/2

==OLD POST== Firstly there is a typo here.

In your else statement you are using non matching tags. It should be alert("in progress");

Lastly your if statement is looking for a, e, i, o, u as the first letter. Your textbox's first letter is "W".

Are you trying to check all values in the input and see if any is a vowel?

Irrelevant stuff from my original post: (I didn't know that br tag closing was only in xhtml... jsfiddle prompted me for this error and i figured all html had.)


All the "br" tags are not closed, they should be:

<br />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM