-1

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)"?
halfer
  • 19,824
  • 17
  • 99
  • 186
  • The error message will tell you exactly what line and character within the line it's having trouble with. What do you see at that line and character position? – T.J. Crowder Aug 05 '21 at 16:58
  • WHat is `function doSaveAs(button) let g="Elton" let p = "0767554433" function save(g,p);` – epascarello Aug 05 '21 at 16:59
  • 1
    And you just undid my edit..... – epascarello Aug 05 '21 at 16:59
  • Hi! When you were asking your question, there was a big orange **How to Format** box to the right of the text area with useful info in it. There was also a toolbar full of formatting aids. And a **[?]** button giving formatting help. *And* a preview area showing what your post would look like when posted, between the text area and the Post Your Question button (so that you'd have to scroll past it to find the button, so you'd look at it). Making your post clear, and showing that you took the time to do so, improves your chances of getting good answers. – T.J. Crowder Aug 05 '21 at 16:59
  • i see at line 61 the function Saveas is trying to Save a contact as – Claudiu Piturca Aug 05 '21 at 16:59
  • 1
    will know that for next time TJ – Claudiu Piturca Aug 05 '21 at 17:00
  • sorry epascarello it didn't show me that – Claudiu Piturca Aug 05 '21 at 17:00
  • For the onclick I am guessing doSave !== doSaveAs unless you have a function doSave somewhere, also not sure what that random `function doSaveAs(button` is at the end. – epascarello Aug 05 '21 at 17:01
  • A tool like eslint will help greatly in your IDE – epascarello Aug 05 '21 at 17:02
  • the function saveas is made to save the contact for the contact phone app basically i'm trying to do a contact app with react – Claudiu Piturca Aug 05 '21 at 17:05
  • Does this answer your question? [SyntaxError: Unexpected Identifier in Chrome's Javascript console](https://stackoverflow.com/questions/5000114/syntaxerror-unexpected-identifier-in-chromes-javascript-console) – Michael Freidgeim Mar 20 '23 at 12:24

1 Answers1

0

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.

gnuself
  • 31
  • 2