告诉我们发生了什么:
My code is write according to the requirements . I dont understand whats wrong. who can help me look at it? The three function is it undefined.
你目前的代码
function normalizeUnits(manifest){
let newmainfest = {...manifest};
if (newmainfest.unit === "lb"){
newmainfest.weight = newmainfest.weight * 0.45;
newmainfest.unit = "kg";
}
return newmainfest;
}
let manifest ={
containerId: 55,
destination: "Carmel",
weight: 400,
unit: "lb",
hazmat: false
}
console.log(normalizeUnits(manifest));
function validateManifest(manifest){
let newmainfest = {...manifest};
let result = {};
if(!("containerId" in newmainfest)){
result.containerId ="Missing";
}else if(!Number.isInteger(newmainfest.containerId) || newmainfest.containerId <= 0 ){
result.containerId = "Invalid";
}
if (!("destination" in newmainfest)){
result.destination ="Missing"
}else if (typeof newmainfest.destination !== "string" || newmainfest.destination.trim() === ""){
result.destination = "Invalid";
}
if (!("weight" in newmainfest)){
result.weight = "Missing";
}else if(typeof newmainfest.weight !== "number" || Number.isNaN(newmainfest.weight) ||
newmainfest.weight <= 0){
result.weight = "Invalid";
}
if(!("unit" in newmainfest)){
result.unit = "Missing";
}else if (newmainfest.unit !=="lb" && newmainfest.unit !=="kg"){
result.unit ="Invalid"
}
if(!("hazmat" in newmainfest)){
result.hazmat ="Missing";
}else if(typeof newmainfest.hazmat !== "boolean"){
result.hazmat = "Invalid";
}
return result;
}
console.log(validateManifest(manifest));
function processManifest(manifest){
let validation = validateManifest(manifest);
if(typeof manifest === "object" &&
manifest !== null &&
validation.containerId !=="Invalid"&& validation.weight !=="Invalid"&&
validation.unit !=="Invalid" &&
validation.hazmat !=="Invalid") {
console.log(`Validation success: ${manifest.containerId}`);
console.log(`Total weight: ${manifest.weight} kg`)
}
}
console.log(processManifest(manifest));
你的浏览器信息:
用户代理是:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/154.0.0.0 Safari/537.36 Edg/154.0.0.0
挑战信息:
创建货物清单验证器 - 构建货物清单验证器