2016-04-26 64 views
-3

這是我迄今爲止所做的工作,我需要在()中添加解決方案。我知道我需要添加for循環,但我不知道在哪裏?我有什麼要添加到同一段打印3次?

function getrandomnumber(min,max,notin) 
{ 
    return min+Math.floor((max-min+1)*Math.random()) 
} 

function roundnumber(num) 
{ 
    return Math.round(num/10)/100 
} 

{ 
    var a=getrandomnumber(50000,10000,"") 
    var b=getrandomnumber(10,100,"") 
    var c=getrandomnumber(50000,10000,"") 
    var d=getrandomnumber(10,100,"") 

    var total=(d-b)/(a-c) 

    var str= "Luis's family decides to rent a hall for her " 
    var s1= "retirement party. Pin Hall charges $"+a+" for " 
    var s2= "the hall and $"+b+" per meal. Bloom place " 
    var s3= "charges $"+c+" for the hall and $"+d+" per " 
    var s4= "meal. Find the number of guests for which the charges are the same at both halls. " 

    document.write(str+s1+s2+s3+s4); 
} 

document.write("<br><br>solution()"); 
+1

請仔細閱讀[問]一個很好的問題。我不清楚你的問題是什麼。 –

+0

因爲你的編輯並沒有真正改善這個問題。我仍然不知道你在努力達到什麼目的。 –

+0

簡單地把你的代碼放在一個函數裏都可以調用循環裏面的函數嗎? 'function solution(){/ * code here * /}; for(/ * loop header * /){solution(); }'。 –

回答

0

我不明白你在嘗試什麼,你想做這個例子嗎?

function getrandomnumber(min,max,notin){ 
    return min+Math.floor((max-min+1)*Math.random()) 
} 

function roundnumber(num){ 
    return Math.round(num/10)/100 
} 

function solution(){ 
    var a=getrandomnumber(50000,10000,"") 
    var b=getrandomnumber(10,100,"") 
    var c=getrandomnumber(50000,10000,"") 
    var d=getrandomnumber(10,100,"") 

    var total=(d-b)/(a-c) 

    var str= "Luis's family decides to rent a hall for her " 
    var s1= "retirement party. Pin Hall charges $"+a+" for " 
    var s2= "the hall and $"+b+" per meal. Bloom place " 
    var s3= "charges $"+c+" for the hall and $"+d+" per " 
    var s4= "meal. Find the number of guests for which the charges are the same at both halls. " 

    return (str+s1+s2+s3+s4); 
} 

document.write(solution())` 

https://jsfiddle.net/cq3uyLtv/

+0

是的,所以下一步是我想添加一個解決方案(回答)這個詞的問題 –