Skip to content

How to fix this “Syntax error:Unexpected identifier”?

I am trying to make an js contact app program that has to save a Contact number and phone and I get this error “Unexpected identifier at line 61”.

I don’t know where seems to be the ending point, how can I solve this? Here is my code:

class Contact {
    constructor(props) {
        this.state = {items:this.props.contacts};
        this.getContacts(); }
     getContacts = () => {
        fetch('http://dev.samples.com/getcontacts.php')
            .then(rsp=>rsp.json())
            .then(response =>{
                this.setState({items:response.data});
                console.log(response.data)
            })
    }
}
    this.setState({items:response.data});
     handleChange(e);
       if(e.target.name == 'name'){
           this.setState({currentContact : { name: e.target.value}})
       }
       if(e.target.name == 'email'){
           this.setState({currentContact : { email: e.target.value}})
       }
       if(e.target.name == 'phone'){
           this.setState({currentContact : { phone: e.target.value}})
       }
       if(e.target.name == 'notes'){
           this.setState({currentContact: {notes: e.target.value}});
       }
        if(e.target.name == 'id'){
            if(e.target.value != undefined || e.target.value != ''){
                this.setState({currentContact : { id: e.target.value}});
                console.log(e.target.value);
            }
        }
        class Prop {
        constructor(props){
        this.state = {currentContact: this.props.currentContact};
        this.currentContact = this.props.currentContact;
        this.id = this.props.currentContact.id;
        this.handleSubmit = this.handleSubmit.bind(this);
        this.handleChange = this.handleChange.bind(this);
    }
}
 function save() 
{ 
var x = button.SaveContact();
var y =  document.open("contact app.html"); 
x.save(contact.txt);
button.Save.appendChild(1);
} 
var Name='Stefan',
Phone="078345678"
function doSaveAs(){
    if (document.execCommand){
        document.execCommand("SaveAs")
    }
    else {
        alert("Save-feature available only in Internet 5.x.")
    }
}
function doSaveAs(button)
let g="Elton"
let p = "0767554433"
function save(g,p);

Also I get this error too when I try to save the contact

:"contact app.html?id={this.id}%2F&name=Stefan&phone=0785678901:31 Uncaught ReferenceError: doSave is not defined
?
    at HTMLInputElement.onclick (contact app.html?id={this.id}%2F&name=Stefan&phone=0785678901:31)"?

Answer

Not really much of a JavaScript developer, but I think you need to review function definitions and how to call them. Reason being it looks as though you started to define doSaveAs as a new function then continued on to other code. Was probably expecting a code block following that. Beyond that, I don’t know the scope of what you’re trying to accomplish.