public/js/questions.js
// edit question with fetch put method
edit question with fetch put method
edit question with fetch put method
function editQuestion(event) {
    event.preventDefault()
    let questionId = this.getAttribute('data-id')
    let quiz_id = document.getElementById('quiz-id').textContent
    let question = document.getElementById('question').value
    let answer = document.getElementById('answer').value
    let choice_a = document.getElementById('choice_a').value
    let choice_b = document.getElementById('choice_b').value
    let choice_c = document.getElementById('choice_c').value
    console.log(question + " put route")
    fetch(`/questions/edit/${questionId}`, {
        method: 'PUT',
        body: JSON.stringify({ question, answer, choice_a, choice_b, choice_c, quiz_id }),
        headers: {
            'Content-Type': 'application/json',
        },
    })
        .then(res => {
            console.log(res)
            window.location.reload()
        })
        .catch(err => console.log(err))
}
function editQuestion ( event ) { event . preventDefault ( ) let questionId = this . getAttribute ( 'data-id' ) let quiz_id = document . getElementById ( 'quiz-id' ) . textContent let question = document . getElementById ( 'question' ) . value let answer = document . getElementById ( 'answer' ) . value let choice_a = document . getElementById ( 'choice_a' ) . value let choice_b = document . getElementById ( 'choice_b' ) . value let choice_c = document . getElementById ( 'choice_c' ) . value console . log ( question + " put route" ) fetch ( ` ${ questionId } ` , { method : 'PUT' , body : JSON . stringify ( { question , answer , choice_a , choice_b , choice_c , quiz_id } ) , headers : { 'Content-Type' : 'application/json' , } , } ) . then ( res => { console . log ( res ) window . location . reload ( ) } ) . catch ( err => console . log ( err ) ) }
edit question with fetch put method
edit question with fetch put method