2017-09-18 154 views
-1

對象屬性,我需要有一些年齡小於16添加第二個人對我else語句返回它的字符串。我將如何添加這個?撥打IF語句條件

function canDrive(name, age) { 
    var person = { 
    name: "Stefano", 
    age: 24, 
    }; 

    if (person.age => 16) { 
     return name + " is old enough to drive."; 
    } 
    else { 
     return name + " is not old enough to drive."; 
    } 
} 
+0

'person.age' .... –

+0

(person.age> = 16) – marvel308

+0

「人」是一個對象。嘗試'如果(person.age> = 16)' – Rajesh

回答

0
  1. 變化這樣>= if語句比較。
  2. 又通的唯一號碼,年齡,不是一個字符串,這意味着無需添加''年齡。
  3. 您已經通過function.so如果傳遞變量不需要加人對象

function canDrive(name, age) { 
 
    if (age >= 16) { 
 
    return name + " is old enough to drive."; 
 
    } else { 
 
    return name + " is not old enough to drive."; 
 
    } 
 
} 
 

 
console.log(canDrive('ram',12)) 
 
console.log(canDrive('vj',22))

0

你不僅可以從person.age得到年齡。這裏的人是不是對象變量

if(person.age >= 16) { } else { } 
+0

@Galwayshannon '=>'不是[關係運算符](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators#Relational_operators)... – Teemu