Search code examples
javascriptnew-operator

"Missing ) after..." on a line, Javascript


So I am creating a "Silly Story Generator" in Javascript and after fixing a few errors that popped up I encountered "SyntaxError: missing ) after argument list"

After reading more about it I learned that it occurs when there is an error with how a function is called. This might be a typo, a missing operator, or an unescaped string.

I checked my code and I cannot seem to find the mistake, string on line 38 looks okay. Thank you.


randomize.addEventListener('click', result);

function result() {
    if (customName.value !== '') {
        let name = customName.value;

    }
    if (document.getElementById("uk").checked) {
        let weight = Math.round(300);
        let temperature = Math.round(94);
    }
    story.text = ""
    story.style.visbility = 'visible';


    var newStory = storyText;

    let xItem = randomValueFromArray;
    let yItem = randomValueFromArray;
    let zItem = randomValueFromArray;

    function newStory(buttonPress) {
        newStory.contentString.replace("insertX", "insertY", "insertZ")
        content.contentString.replace("xItem ", "yItem", "zItem");
    }
}



Solution

  • Your Code is Badly formatted.

    At newStory.contentString.replace("insertX", "insertY", "insertZ";) You had a semi-colon inside the the parenthesis. You are also missing two curly braces near the end.

    I suggest getting a good IDE or using the formatting features that come with the one you use.

    randomize.addEventListener('click', result);
    
    function result() {
        if (customName.value !== '') {
            let name = customName.value;
    
        }
        if (document.getElementById("uk").checked) {
            let weight = Math.round(300);
            let temperature = Math.round(94);
        }
        story.text = ""
        story.style.visbility = 'visible';
    
    
        var newStory = storyText;
    
        let xItem = randomValueFromArray;
        let yItem = randomValueFromArray;
        let zItem = randomValueFromArray;
    
        function newStory(buttonPress) {
            newStory.contentString.replace("insertX", "insertY", "insertZ")
            content.contentString.replace("xItem ", "yItem", "zItem");
        }
    }