JS alert | Sololearn: Learn to code for FREE!

+1

JS alert

I need to put an alert that returns to the google page if the user does not accept the terms and conditions (excuse the ignorance)

2 Answers

New Answer

+4

let agree = confirm("Do you agree ?") console.log(agree)

0

Jorge Adrian Matamoros Montenegro hi, The answer given by DLite points you in the good direction but to complete : The user action stored in the variable through confirm ("....") will be a Boolean value > If user press ok -> true (-> 1) so agree=true >If user press cancel -> false (-> 0) so agree= false So by the end you could use a if statement: if(agree){ // Some code for whatever... } else{ window.location.replace("http://www.google.com"); } Or ternary operator: agree ? Some code : window.location.replace("http://www.google.com"); https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage https://www.developintelligence.com/blog/2016/04/javascript-redirect-how-to-redirect-a-web-page-with-javascript/