is the problem with the code if appear like that    //get Element by Id var reserve = document.getElementById("submit1"); //Add click response event for Reserve button reserve.addEventListener('click',save);   //save data function save(){ var reserve = new Object; reserve.keyname = document.getElementById("name").value; reserve.email = document.getElementById("email").value; reserve.date = document.getElementById("date").value;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

What is the problem with the code if appear like that 

 

//get Element by Id

var reserve = document.getElementById("submit1");

//Add click response event for Reserve button

reserve.addEventListener('click',save);

 

//save data
function save(){
var reserve = new Object;
reserve.keyname = document.getElementById("name").value;
reserve.email = document.getElementById("email").value;
reserve.date = document.getElementById("date").value;
reserve.time = document.getElementById("time").value;
reserve.venue = document.getElementById("venue").value;
var str = JSON.stringify(reserve);

// change time to seconds
var nowSeconds = time_to_sec(reserve.time);

// set opening hours
var targetSeconds = 23 * 3600;
var targetSeconds1 = 8 * 3600;

//To determine if it is during opening hours
if(nowSeconds > targetSeconds || nowSeconds < targetSeconds1){
alert("Sorry, the opening hours are from 8am until 11pm!");
}else{
//Check whether the venue and time selected by the user have been booked
if(check(reserve) == false){
}else{
localStorage.setItem(reserve.keyname,str);
alert("Added successfully");
}
}

}

//Check whether the venue and time selected by the user have been booked
function check(reserve){
//Compare with all the data in the database and check the conflict time
for(i=0;i<localStorage.length;i++){
var keyname = localStorage.key(i);
var str = localStorage.getItem(keyname);
var data = JSON.parse(str);

if(reserve.date == data.date && reserve.venue == data.venue){
var ScheduledSeconds = time_to_sec(data.time);
var nowSeconds = time_to_sec(reserve.time);
// time in this scope can not be reserve
var duration = ScheduledSeconds + 1 * 3600;
var duration1 = ScheduledSeconds - 1 * 3600;
// Tell the user the optional time
var targettime = ScheduledSeconds - 1 * 3600;
var targettime1 = ScheduledSeconds + 1 * 3600;

if(nowSeconds >= ScheduledSeconds && nowSeconds <= duration){

alert('The venue of ' + reserve.venue + ' on ' + data.time + ' aleady by booked! '
+ 'please change to ' + changetime(targettime1) + ' or another time! Thank for you cooperation');
return false;

}else if(nowSeconds <= ScheduledSeconds && nowSeconds >= duration1){
alert('The venue of ' + reserve.venue + ' on ' + data.time + ' aleady by booked! '
+ 'please change to ' + changetime(targettime) + ' or another time! Thank for you cooperation');
return false;
}

}
}
}
// Change time to seconds
var time_to_sec = function (time) {
var hour = time.split(':')[0];
var min = time.split(':')[1];

var s = Number(hour*3600) + Number(min*60);
return s;
};

//change seconds back to time
function changetime(value) {
var secondTime = parseInt(value);// 秒
var minuteTime = 0;// 分
var hourTime = 0;// 小时
if(secondTime > 60) {
//If the number of seconds is greater than 60, convert the number of seconds to an integer
minuteTime = parseInt(secondTime / 60);
secondTime = parseInt(secondTime % 60);

if(minuteTime > 60) {
hourTime = parseInt(minuteTime / 60);
minuteTime = parseInt(minuteTime % 60);
}
}

var time = "" + parseInt(secondTime);

if(minuteTime > 0) {
time = "" + parseInt(minuteTime) + ":" + time;
}
if(hourTime > 0) {
time = "" + parseInt(hourTime) + ":" + time;
}
return time;
}

//find data
function find(){

var searchName = document.getElementById("search").value;
var str = localStorage.getItem(searchName);
var result = document.getElementById("result");

var reserve = JSON.parse(str);
//Determine whether it is empty
if(str == null){
result.innerHTML = "Can not find the record! "
}else
result.innerHTML = "&nbsp;&nbsp;"+reserve.keyname+"&nbsp;&nbsp;"+reserve.email+"&nbsp;&nbsp;"+reserve.date+"&nbsp;&nbsp;"+reserve.time+"&nbsp;&nbsp;"+reserve.venue+"</td></tr>";
}
//Load all the data
function loadAll(){
var list = document.getElementById("list");
//Output all data in a loop
if(localStorage.length>0){
var result = "<table border='1'>";
result += "<tr><td>name</td><td>email</td><td>date</td><td>time</td><td>venue</td><td>delete</td></tr>";
for(var i=0;i<localStorage.length;i++){

var keyname = localStorage.key(i);
var str = localStorage.getItem(keyname);
var reserve = JSON.parse(str);

result += "<tr>" +
"<td>"+reserve.keyname+"</td>"+
"<td>"+reserve.email+"</td>"+
"<td>"+reserve.date+"</td>"+
"<td>"+reserve.time+"</td>"+
"<td>"+reserve.venue+"</td>"+
"<td><input type=button value=delet onclick=del("+"'"+keyname+"'"+") ></td>" +
"</tr>";

}
//Add result to the view
result += "</table>";
list.innerHTML = result;
}else{
list.innerHTML = "Nothing here……";
}
}
//delete data
function del(keyname) {
localStorage.removeItem(keyname);
alert("successfully deleted!");
loadAll();
}


//Delete all data;
//localStorage.clear();

Uncaught SyntaxError: Unexpected token u in JSON at reservationform.html:1
position 0
at JSON.parse (<anonymous>)
at check (data.js:52)
at HTMLButtonElement.save (data.js:37)
Uncaught SyntaxError: Unexpected token u in JSON at
position 0
at JSON.parse (<anonymous>)
at check (data.js:52)
at HTMLButtonElement.save (data.js:37)
reservationform.html:1
Uncaught SyntaxError: Unexpected token u in JSON at
position 0
at JSON.parse (<anonymous>)
at check (data.js:52)
at HTMLButtonElement.save (data.js:37)
reservationform.html:1
Uncaught SyntaxError: Unexpected token u in JSON at
position 0
at JSON.parse (<anonymous>)
at check (data.js:52)
at HTMLButtonElement.save (data.js:37)
reservationform.html:1
Uncaught SyntaxError: Unexpected token u in JSON at
position 0
at JSON.parse (<anonymous>)
at loadAll (data.js:140)
at HTMLButtonElement.onclick (reservationform.html:99)
reservationform.html:1
10:11 PM
a 4») ENG
10/4/2021
Transcribed Image Text:Uncaught SyntaxError: Unexpected token u in JSON at reservationform.html:1 position 0 at JSON.parse (<anonymous>) at check (data.js:52) at HTMLButtonElement.save (data.js:37) Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>) at check (data.js:52) at HTMLButtonElement.save (data.js:37) reservationform.html:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>) at check (data.js:52) at HTMLButtonElement.save (data.js:37) reservationform.html:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>) at check (data.js:52) at HTMLButtonElement.save (data.js:37) reservationform.html:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>) at loadAll (data.js:140) at HTMLButtonElement.onclick (reservationform.html:99) reservationform.html:1 10:11 PM a 4») ENG 10/4/2021
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Running Time of Application
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education